LibreOffice Module sw (master)  1
mailmergehelper.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <swtypes.hxx>
21 #include <mailmergehelper.hxx>
22 #include <mmconfigitem.hxx>
23 #include <docsh.hxx>
24 #include <sfx2/filedlghelper.hxx>
25 #include <sfx2/docfile.hxx>
26 #include <com/sun/star/sdbc/SQLException.hpp>
27 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28 #include <com/sun/star/sdb/XColumn.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
31 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
32 #include <com/sun/star/mail/MailServiceProvider.hpp>
33 #include <com/sun/star/mail/XSmtpService.hpp>
35 #include <o3tl/safeint.hxx>
36 #include <vcl/event.hxx>
37 #include <vcl/settings.hxx>
38 #include <vcl/svapp.hxx>
39 
40 #include <sfx2/passwd.hxx>
41 
42 #include <dbui.hrc>
43 #include <strings.hrc>
44 
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::sdb;
49 using namespace ::com::sun::star::sdbc;
50 using namespace ::com::sun::star::sdbcx;
51 
53 {
54 
55 OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter)
56 {
57  ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
58  FileDialogFlags::NONE,
59  SwDocShell::Factory().GetFactoryName(), SfxFilterFlags::NONE, SfxFilterFlags::NONE, pParent);
60 
61  if (aDialog.Execute()!=ERRCODE_NONE)
62  {
63  return OUString();
64  }
65 
66  rFilter = aDialog.GetRealFilter();
67  uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDialog.GetFilePicker();
68  return xFP->getSelectedFiles().getConstArray()[0];
69 }
70 
71 /*
72  simple address check: check for '@'
73  for at least one '.' after the '@'
74  and for at least two characters before and after the dot
75 */
76 bool CheckMailAddress( const OUString& rMailAddress )
77 {
78  const sal_Int32 nPosAt = rMailAddress.indexOf('@');
79  if (nPosAt<0 || rMailAddress.lastIndexOf('@')!=nPosAt)
80  return false;
81  const sal_Int32 nPosDot = rMailAddress.indexOf('.', nPosAt);
82  return !(nPosDot<0 || nPosDot-nPosAt<3 || rMailAddress.getLength()-nPosDot<3);
83 }
84 
85 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
86  SwMailMergeConfigItem const & rConfigItem,
87  uno::Reference< mail::XMailService >& rxInMailService,
88  const OUString& rInMailServerPassword,
89  const OUString& rOutMailServerPassword,
90  weld::Window* pDialogParentWindow )
91 {
92  uno::Reference< mail::XSmtpService > xSmtpServer;
93  uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
94  try
95  {
96  uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
97  mail::MailServiceProvider::create( xContext ) );
98  xSmtpServer.set(xMailServiceProvider->create(mail::MailServiceType_SMTP), uno::UNO_QUERY);
99 
100  uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
101 
102  if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
103  {
104  uno::Reference< mail::XMailService > xInMailService =
105  xMailServiceProvider->create(
106  rConfigItem.IsInServerPOP() ?
107  mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
108  //authenticate at the POP or IMAP server first
109  OUString sPasswd = rConfigItem.GetInServerPassword();
110  if(!rInMailServerPassword.isEmpty())
111  sPasswd = rInMailServerPassword;
112  uno::Reference<mail::XAuthenticator> xAuthenticator =
113  new SwAuthenticator(
114  rConfigItem.GetInServerUserName(),
115  sPasswd,
116  pDialogParentWindow);
117 
118  xInMailService->addConnectionListener(xConnectionListener);
119  //check connection
120  uno::Reference< uno::XCurrentContext> xConnectionContext =
122  rConfigItem.GetInServerName(),
123  rConfigItem.GetInServerPort(),
124  "Insecure");
125  xInMailService->connect(xConnectionContext, xAuthenticator);
126  rxInMailService = xInMailService;
127  }
128  uno::Reference< mail::XAuthenticator> xAuthenticator;
129  if(rConfigItem.IsAuthentication() &&
130  !rConfigItem.IsSMTPAfterPOP() &&
131  !rConfigItem.GetMailUserName().isEmpty())
132  {
133  OUString sPasswd = rConfigItem.GetMailPassword();
134  if(!rOutMailServerPassword.isEmpty())
135  sPasswd = rOutMailServerPassword;
136  xAuthenticator =
137  new SwAuthenticator(rConfigItem.GetMailUserName(),
138  sPasswd,
139  pDialogParentWindow);
140  }
141  else
142  xAuthenticator = new SwAuthenticator();
143  //just to check if the server exists
144  xSmtpServer->getSupportedConnectionTypes();
145  //check connection
146 
147  uno::Reference< uno::XCurrentContext> xConnectionContext =
149  rConfigItem.GetMailServer(),
150  rConfigItem.GetMailPort(),
151  rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
152  xSmtpServer->connect(xConnectionContext, xAuthenticator);
153  rxInMailService = xSmtpServer;
154  }
155  catch (const uno::Exception&)
156  {
157  OSL_FAIL("exception caught");
158  }
159  return xSmtpServer;
160 }
161 
162 } //namespace
163 
165 {
166  std::vector< OUString > aAddresses;
167  sal_uInt16 nRows;
168  sal_uInt16 nColumns;
169  sal_uInt16 nSelectedAddress;
171 
173  nRows(1),
174  nColumns(1),
175  nSelectedAddress(0),
176  bEnableScrollBar(false)
177  {
178  }
179 };
180 
182  const OUString& rAddress,
183  SwMailMergeConfigItem const & rConfigItem,
184  const Sequence< OUString>* pAssignments)
185 {
186  //find the column names in the address string (with name assignment!) and
187  //exchange the placeholder (like <Firstname>) with the database content
188  //unassigned columns are expanded to <not assigned>
189  Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
190  Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
191  Sequence< OUString> aAssignment = pAssignments ?
192  *pAssignments :
193  rConfigItem.GetColumnAssignment(
194  rConfigItem.GetCurrentDBData() );
195  const OUString* pAssignment = aAssignment.getConstArray();
196  const std::vector<std::pair<OUString, int>>& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
197  OUString sNotAssigned = "<" + SwResId(STR_NOTASSIGNED) + ">";
198 
199  bool bIncludeCountry = rConfigItem.IsIncludeCountry();
200  const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
201  bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
202  OUString sCountryColumn;
203  if( bSpecialReplacementForCountry )
204  {
205  sCountryColumn = rDefHeaders[MM_PART_COUNTRY].first;
206  Sequence< OUString> aSpecialAssignment =
207  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
208  if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
209  sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
210  }
211 
212  SwAddressIterator aIter(rAddress);
213  OUStringBuffer sAddress;
214  while(aIter.HasMore())
215  {
216  SwMergeAddressItem aItem = aIter.Next();
217  if(aItem.bIsColumn)
218  {
219  //get the default column name
220 
221  //find the appropriate assignment
222  OUString sConvertedColumn = aItem.sText;
223  auto nSize = std::min(sal_uInt32(rDefHeaders.size()), sal_uInt32(aAssignment.getLength()));
224  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
225  {
226  if (rDefHeaders[nColumn].first == aItem.sText &&
227  !pAssignment[nColumn].isEmpty())
228  {
229  sConvertedColumn = pAssignment[nColumn];
230  break;
231  }
232  }
233  if(!sConvertedColumn.isEmpty() &&
234  xColAccess.is() &&
235  xColAccess->hasByName(sConvertedColumn))
236  {
237  //get the content and exchange it in the address string
238  Any aCol = xColAccess->getByName(sConvertedColumn);
239  Reference< XColumn > xColumn;
240  aCol >>= xColumn;
241  if(xColumn.is())
242  {
243  try
244  {
245  OUString sReplace = xColumn->getString();
246 
247  if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
248  {
249  if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
250  aItem.sText = sReplace;
251  else
252  aItem.sText.clear();
253  }
254  else
255  {
256  aItem.sText = sReplace;
257  }
258  }
259  catch (const sdbc::SQLException&)
260  {
261  OSL_FAIL("SQLException caught");
262  }
263  }
264  }
265  else
266  {
267  aItem.sText = sNotAssigned;
268  }
269 
270  }
271  sAddress.append(aItem.sText);
272  }
273  return sAddress.makeStringAndClear();
274 }
275 
276 SwAddressPreview::SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xWindow)
277  : pImpl(new SwAddressPreview_Impl())
278  , m_xVScrollBar(std::move(xWindow))
279 {
280  m_xVScrollBar->set_user_managed_scrolling();
281  m_xVScrollBar->connect_vadjustment_changed(LINK(this, SwAddressPreview, ScrollHdl));
282 }
283 
285 {
286 }
287 
289 {
290  Invalidate();
291 }
292 
293 void SwAddressPreview::AddAddress(const OUString& rAddress)
294 {
295  pImpl->aAddresses.push_back(rAddress);
296  UpdateScrollBar();
297 }
298 
299 void SwAddressPreview::SetAddress(const OUString& rAddress)
300 {
301  pImpl->aAddresses.clear();
302  pImpl->aAddresses.push_back(rAddress);
303  m_xVScrollBar->set_vpolicy(VclPolicyType::NEVER);
304  Invalidate();
305 }
306 
308 {
309  OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAddresses.size(), "selection invalid");
310  return pImpl->nSelectedAddress;
311 }
312 
313 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
314 {
315  OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAddresses.size(), "selection invalid");
316  pImpl->nSelectedAddress = nSelect;
317  // now make it visible...
318  sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
319  sal_uInt16 nStartRow = m_xVScrollBar->vadjustment_get_value();
320  if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
321  m_xVScrollBar->vadjustment_set_value(nSelectRow);
322 }
323 
325 {
326  pImpl->aAddresses.clear();
327  pImpl->nSelectedAddress = 0;
328  UpdateScrollBar();
329 }
330 
332 {
333  pImpl->aAddresses[pImpl->nSelectedAddress] = rNew;
334  Invalidate();
335 }
336 
338 {
339  pImpl->aAddresses.erase(pImpl->aAddresses.begin() + pImpl->nSelectedAddress);
340  if(pImpl->nSelectedAddress)
341  --pImpl->nSelectedAddress;
342  UpdateScrollBar();
343  Invalidate();
344 }
345 
346 void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
347 {
348  pImpl->nRows = nRows;
349  pImpl->nColumns = nColumns;
350  UpdateScrollBar();
351 }
352 
354 {
355  pImpl->bEnableScrollBar = true;
356 }
357 
359 {
360  if (pImpl->nColumns)
361  {
362  sal_uInt16 nResultingRows = static_cast<sal_uInt16>(pImpl->aAddresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
363  ++nResultingRows;
364  auto nValue = m_xVScrollBar->vadjustment_get_value();
365  if (nValue > nResultingRows)
366  nValue = nResultingRows;
367  m_xVScrollBar->set_vpolicy(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows ? VclPolicyType::ALWAYS : VclPolicyType::NEVER);
368  m_xVScrollBar->vadjustment_configure(nValue, 0, nResultingRows, 1, 10, pImpl->nRows);
369  }
370 }
371 
373 {
374  const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
375  rRenderContext.SetFillColor(rSettings.GetWindowColor());
376  rRenderContext.SetLineColor(COL_TRANSPARENT);
377  rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), GetOutputSizePixel()));
378  Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
379  rRenderContext.SetLineColor(aPaintColor);
380 
381  if (vcl::Window* pDefaultDevice = dynamic_cast<vcl::Window*>(Application::GetDefaultDevice()))
382  pDefaultDevice->SetPointFont(rRenderContext, GetDrawingArea()->get_font());
383  vcl::Font aFont(rRenderContext.GetFont());
384  aFont.SetColor(aPaintColor);
385  rRenderContext.SetFont(aFont);
386 
387  Size aSize(GetOutputSizePixel());
388  sal_uInt16 nStartRow = 0;
389  if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER)
390  {
391  aSize.AdjustWidth(-m_xVScrollBar->get_vscroll_width());
392  nStartRow = m_xVScrollBar->vadjustment_get_value();
393  }
394  Size aPartSize(aSize.Width() / pImpl->nColumns,
395  aSize.Height() / pImpl->nRows);
396  aPartSize.AdjustWidth( -2 );
397  aPartSize.AdjustHeight( -2 );
398 
399  sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
400  const sal_uInt16 nNumAddresses = static_cast<sal_uInt16>(pImpl->aAddresses.size());
401  for (sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
402  {
403  for (sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
404  {
405  if (nAddress >= nNumAddresses)
406  break;
407  Point aPos(nCol * aPartSize.Width(),
408  nRow * aPartSize.Height());
409  aPos.Move(1, 1);
410  bool bIsSelected = nAddress == pImpl->nSelectedAddress;
411  if ((pImpl->nColumns * pImpl->nRows) == 1)
412  bIsSelected = false;
413  OUString adr(pImpl->aAddresses[nAddress]);
414  DrawText_Impl(rRenderContext, adr, aPos, aPartSize, bIsSelected);
415  ++nAddress;
416  }
417  }
418  rRenderContext.SetClipRegion();
419 }
420 
422 {
423  if (rMEvt.IsLeft() && pImpl->nRows && pImpl->nColumns)
424  {
425  //determine the selected address
426  const Point& rMousePos = rMEvt.GetPosPixel();
427  Size aSize(GetOutputSizePixel());
428  Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
429  sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
430  if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER)
431  {
432  nRow += m_xVScrollBar->vadjustment_get_value();
433  }
434  sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
435  sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
436 
437  if( nSelect < pImpl->aAddresses.size() &&
438  pImpl->nSelectedAddress != static_cast<sal_uInt16>(nSelect))
439  {
440  pImpl->nSelectedAddress = static_cast<sal_uInt16>(nSelect);
441  m_aSelectHdl.Call(nullptr);
442  }
443  Invalidate();
444  }
445  return true;
446 }
447 
449 {
450  sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
451  bool bHandled = false;
452  if (pImpl->nRows && pImpl->nColumns)
453  {
454  sal_uInt32 nSelectedRow = pImpl->nSelectedAddress / pImpl->nColumns;
455  sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress - (nSelectedRow * pImpl->nColumns);
456  switch(nKey)
457  {
458  case KEY_UP:
459  if(nSelectedRow)
460  --nSelectedRow;
461  bHandled = true;
462  break;
463  case KEY_DOWN:
464  if(pImpl->aAddresses.size() > o3tl::make_unsigned(pImpl->nSelectedAddress + pImpl->nColumns))
465  ++nSelectedRow;
466  bHandled = true;
467  break;
468  case KEY_LEFT:
469  if(nSelectedColumn)
470  --nSelectedColumn;
471  bHandled = true;
472  break;
473  case KEY_RIGHT:
474  if(nSelectedColumn < o3tl::make_unsigned(pImpl->nColumns - 1) &&
475  pImpl->aAddresses.size() - 1 > pImpl->nSelectedAddress )
476  ++nSelectedColumn;
477  bHandled = true;
478  break;
479  }
480  sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
481  if( nSelect < pImpl->aAddresses.size() &&
482  pImpl->nSelectedAddress != static_cast<sal_uInt16>(nSelect))
483  {
484  pImpl->nSelectedAddress = static_cast<sal_uInt16>(nSelect);
485  m_aSelectHdl.Call(nullptr);
486  Invalidate();
487  }
488  }
489  return bHandled;
490 }
491 
492 void SwAddressPreview::DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
493  const Point& rTopLeft, const Size& rSize, bool bIsSelected)
494 {
495  rRenderContext.SetClipRegion(vcl::Region(tools::Rectangle(rTopLeft, rSize)));
496  if (bIsSelected)
497  {
498  //selection rectangle
499  rRenderContext.SetFillColor(COL_TRANSPARENT);
500  rRenderContext.DrawRect(tools::Rectangle(rTopLeft, rSize));
501  }
502  sal_Int32 nHeight = GetTextHeight();
503  Point aStart = rTopLeft;
504  //put it away from the border
505  aStart.Move(2, 2);
506  sal_Int32 nPos = 0;
507  do
508  {
509  rRenderContext.DrawText(aStart, rAddress.getToken(0, '\n', nPos));
510  aStart.AdjustY(nHeight );
511  }
512  while (nPos >= 0);
513 }
514 
516 {
517  //currently the string may either start with a '<' then it's a column
518  //otherwise it's simple text maybe containing a return
519  SwMergeAddressItem aRet;
520  if(!sAddress.isEmpty())
521  {
522  if(sAddress[0] == '<')
523  {
524  aRet.bIsColumn = true;
525  sal_Int32 nClose = sAddress.indexOf('>');
526  OSL_ENSURE(nClose != -1, "closing '>' not found");
527  if( nClose != -1 )
528  {
529  aRet.sText = sAddress.copy(1, nClose - 1);
530  sAddress = sAddress.copy(nClose + 1);
531  }
532  else
533  {
534  aRet.sText = sAddress.copy(1, 1);
535  sAddress = sAddress.copy(1);
536  }
537  }
538  else
539  {
540  sal_Int32 nOpen = sAddress.indexOf('<');
541  sal_Int32 nReturn = sAddress.indexOf('\n');
542  if(nReturn == 0)
543  {
544  aRet.bIsReturn = true;
545  aRet.sText = "\n";
546  sAddress = sAddress.copy(1);
547  }
548  else if(-1 == nOpen && -1 == nReturn)
549  {
550  aRet.sText = sAddress;
551  sAddress.clear();
552  }
553  else
554  {
555  if (nOpen == -1)
556  nOpen = sAddress.getLength();
557  if (nReturn == -1)
558  nReturn = sAddress.getLength();
559  sal_Int32 nTarget = std::min(nOpen, nReturn);
560  aRet.sText = sAddress.copy(0, nTarget);
561  sAddress = sAddress.copy(nTarget);
562  }
563  }
564  }
565  return aRet;
566 
567 }
568 
570 {
571 }
572 
574 {
575  return m_aUserName;
576 }
577 
579 {
580  if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow)
581  {
583  aPasswdDlg.SetMinLen(0);
584  if (RET_OK == aPasswdDlg.run())
585  m_aPassword = aPasswdDlg.GetPassword();
586  }
587  return m_aPassword;
588 }
589 
591  const OUString& rMailServer, sal_Int16 nPort,
592  const OUString& rConnectionType) :
593  m_sMailServer(rMailServer),
594  m_nPort(nPort),
595  m_sConnectionType(rConnectionType)
596 {
597 }
598 
600 {
601 }
602 
604 {
605  uno::Any aRet;
606  if( rName == "ServerName" )
607  aRet <<= m_sMailServer;
608  else if( rName == "Port" )
609  aRet <<= static_cast<sal_Int32>(m_nPort);
610  else if( rName == "ConnectionType" )
611  aRet <<= m_sConnectionType;
612  return aRet;
613 }
614 
616 {
617 }
618 
619 void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
620 {
621 }
622 
623 void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
624 {
625 }
626 
627 void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
628 {
629 }
630 
631 SwMailTransferable::SwMailTransferable(const OUString& rBody, const OUString& rMimeType) :
632  cppu::WeakComponentImplHelper< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
633  m_aMimeType( rMimeType ),
634  m_sBody( rBody ),
635  m_bIsBody( true )
636 {
637 }
638 
640  const OUString& rName, const OUString& rMimeType) :
641  cppu::WeakComponentImplHelper< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
642  m_aMimeType( rMimeType ),
643  m_aURL(rURL),
644  m_aName( rName ),
645  m_bIsBody( false )
646 {
647 }
648 
650 {
651 }
652 
653 uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
654 {
655  uno::Any aRet;
656  if( m_bIsBody )
657  aRet <<= m_sBody;
658  else
659  {
660  Sequence<sal_Int8> aData;
661  SfxMedium aMedium( m_aURL, StreamMode::STD_READ );
662  SvStream* pStream = aMedium.GetInStream();
663  if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
664  {
665  aData.realloc(pStream->TellEnd());
666  pStream->Seek(0);
667  sal_Int8 * pData = aData.getArray();
668  pStream->ReadBytes( pData, aData.getLength() );
669  }
670  aRet <<= aData;
671  }
672  return aRet;
673 }
674 
675 uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
676 {
677  uno::Sequence< datatransfer::DataFlavor > aRet(1);
678  aRet[0].MimeType = m_aMimeType;
679  if( m_bIsBody )
680  {
681  aRet[0].DataType = cppu::UnoType<OUString>::get();
682  }
683  else
684  {
685  aRet[0].HumanPresentableName = m_aName;
686  aRet[0].DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get();
687  }
688  return aRet;
689 }
690 
692  const datatransfer::DataFlavor& aFlavor )
693 {
694  return (aFlavor.MimeType == m_aMimeType);
695 }
696 
697 uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( )
698 {
699  return uno::Reference< beans::XPropertySetInfo >();
700 }
701 
702 void SwMailTransferable::setPropertyValue( const OUString& , const uno::Any& )
703 {
704 }
705 
706 uno::Any SwMailTransferable::getPropertyValue( const OUString& rPropertyName )
707 {
708  uno::Any aRet;
709  if ( rPropertyName == "URL" )
710  aRet <<= m_aURL;
711  return aRet;
712 }
713 
715  const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
716 {
717 }
718 
720  const OUString&,
721  const uno::Reference< beans::XPropertyChangeListener >& )
722 {
723 }
724 
726  const OUString&,
727  const uno::Reference< beans::XVetoableChangeListener >& )
728 {
729 }
730 
732  const OUString& ,
733  const uno::Reference< beans::XVetoableChangeListener >& )
734 {
735 }
736 
738  cppu::WeakComponentImplHelper< mail::XMailMessage>(m_aMutex)
739 {
740 }
741 
743 {
744 }
745 
747 {
748  return m_sSenderName;
749 }
750 
752 {
753  return m_sSenderAddress;
754 }
755 
757 {
758  return m_sReplyToAddress;
759 }
760 
761 void SwMailMessage::setReplyToAddress( const OUString& _replytoaddress )
762 {
763  m_sReplyToAddress = _replytoaddress;
764 }
765 
767 {
768  return m_sSubject;
769 }
770 
771 void SwMailMessage::setSubject( const OUString& _subject )
772 {
773  m_sSubject = _subject;
774 }
775 
776 uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody()
777 {
778  return m_xBody;
779 }
780 
782  const uno::Reference< datatransfer::XTransferable >& rBody )
783 {
784  m_xBody = rBody;
785 }
786 
787 void SwMailMessage::addRecipient( const OUString& rRecipientAddress )
788 {
789  m_aRecipients.realloc(m_aRecipients.getLength() + 1);
790  m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
791 }
792 
793 void SwMailMessage::addCcRecipient( const OUString& rRecipientAddress )
794 {
795  m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
796  m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
797 
798 }
799 
800 void SwMailMessage::addBccRecipient( const OUString& rRecipientAddress )
801 {
802  m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
803  m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
804 }
805 
806 uno::Sequence< OUString > SwMailMessage::getRecipients( )
807 {
808  return m_aRecipients;
809 }
810 
811 uno::Sequence< OUString > SwMailMessage::getCcRecipients( )
812 {
813  return m_aCcRecipients;
814 }
815 
816 uno::Sequence< OUString > SwMailMessage::getBccRecipients( )
817 {
818  return m_aBccRecipients;
819 }
820 
821 void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
822 {
823  m_aAttachments.realloc(m_aAttachments.getLength() + 1);
824  m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
825 }
826 
827 uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
828 {
829  return m_aAttachments;
830 }
831 
832 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
void SetClipRegion()
long Width() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
SwMergeAddressItem Next()
bool HasMore() const
virtual void SAL_CALL setBody(const css::uno::Reference< css::datatransfer::XTransferable > &_body) override
OUString const & GetMailServer() const
std::unique_ptr< weld::ScrolledWindow > m_xVScrollBar
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
SwAddressPreview(std::unique_ptr< weld::ScrolledWindow > xParent)
osl::Mutex m_aMutex
long AdjustWidth(long n)
const char aData[]
Definition: ww8scan.hxx:47
virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor &aFlavor) override
std::unique_ptr< ContentProperties > pData
SwConnectionContext(const OUString &rMailServer, sal_Int16 nPort, const OUString &rConnectionType)
long Height() const
signed char sal_Int8
bool IsSecureConnection() const
css::uno::Sequence< OUString > m_aCcRecipients
virtual sal_uInt64 TellEnd()
OUString & GetExcludeCountry() const
const StyleSettings & GetStyleSettings() const
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Reference< css::datatransfer::XTransferable > m_xBody
OString m_aMimeType
std::vector< OUString > aAddresses
sal_uInt64 Seek(sal_uInt64 nPos)
sal_uInt16 GetCode() const
const SwDBData & GetCurrentDBData() const
virtual short run() override
sal_Int16 GetMailPort() const
virtual css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override
weld::Window * m_pParentWindow
void DrawText_Impl(vcl::RenderContext &rRenderContext, const OUString &rAddress, const Point &rTopLeft, const Size &rSize, bool bIsSelected)
constexpr sal_uInt16 KEY_UP
Size const & GetOutputSizePixel() const
void SetAddress(const OUString &rAddress)
static OutputDevice * GetDefaultDevice()
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
virtual ~SwConnectionContext() override
virtual ~SwAuthenticator() override
void AddAddress(const OUString &rAddress)
The address string is a list of address elements separated by spaces and breaks.
OUString GetRealFilter() const
const vcl::Font & GetFont() const
Link< LinkParamNone *, void > m_aSelectHdl
css::uno::Sequence< OUString > m_aBccRecipients
virtual bool KeyInput(const KeyEvent &rKEvt) override
virtual OUString SAL_CALL getSubject() override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual ~SwAddressPreview() override
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
void DrawRect(const tools::Rectangle &rRect)
bool IsAuthentication() const
OUString const & GetInServerPassword() const
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
sal_Int16 GetInServerPort() const
css::uno::Reference< css::sdbc::XResultSet > const & GetResultSet() const
constexpr sal_uInt16 KEY_DOWN
OUString m_aName
css::uno::Sequence< css::mail::MailAttachment > m_aAttachments
void SetLineColor()
css::uno::Sequence< OUString > m_aRecipients
const std::vector< std::pair< OUString, int > > & GetDefaultAddressHeaders() const
const Color & GetDisableColor() const
virtual void SAL_CALL disconnected(const css::lang::EventObject &aEvent) override
OUString CallSaveAsDialog(weld::Window *pParent, OUString &rFilter)
IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl, weld::ScrolledWindow &, void)
class SAL_NO_VTABLE XPropertySet
virtual OUString SAL_CALL getUserName() override
css::util::URL m_aURL
OUString m_sSenderAddress
void SetFillColor()
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
virtual void SAL_CALL addCcRecipient(const OUString &sRecipientAddress) override
unsigned char sal_Bool
virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor &aFlavor) override
css::uno::Type const & get()
void SelectAddress(sal_uInt16 nSelect)
const AllSettings & GetSettings() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
virtual css::uno::Sequence< OUString > SAL_CALL getRecipients() override
virtual ~SwMailMessage() override
bool IsInServerPOP() const
ErrCode GetErrorCode() const
virtual void SAL_CALL addRecipient(const OUString &sRecipientAddress) override
void SetColor(const Color &)
void SetMinLen(sal_uInt16 Len)
css::uno::Sequence< OUString > GetColumnAssignment(const SwDBData &rDBData) const
constexpr sal_uInt16 KEY_RIGHT
virtual css::uno::Sequence< OUString > SAL_CALL getBccRecipients() override
std::size_t ReadBytes(void *pData, std::size_t nSize)
OUString m_sSenderName
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
OUString const & GetInServerUserName() const
virtual css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getBody() override
SvStream * GetInStream()
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL connected(const css::lang::EventObject &aEvent) override
const vcl::KeyCode & GetKeyCode() const
weld::DrawingArea * GetDrawingArea() const
virtual OUString SAL_CALL getReplyToAddress() override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
OUString m_sReplyToAddress
#define ERRCODE_NONE
void SetFont(const vcl::Font &rNewFont)
virtual ~SwMailTransferable() override
void ReplaceSelectedAddress(const OUString &)
bool IsLeft() const
virtual void SAL_CALL addBccRecipient(const OUString &sRecipientAddress) override
RET_OK
virtual OUString SAL_CALL getSenderAddress() override
virtual void SAL_CALL setReplyToAddress(const OUString &_replytoaddress) override
SwMailTransferable(const OUString &rURL, const OUString &rName, const OUString &rMimeType)
virtual css::uno::Sequence< OUString > SAL_CALL getCcRecipients() override
OUString GetPassword() const
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
const Color & GetWindowColor() const
const Point & GetPosPixel() const
bool IsIncludeCountry() const
virtual css::uno::Any SAL_CALL getValueByName(const OUString &Name) override
Reference< XColumn > xColumn
virtual OUString SAL_CALL getSenderName() override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
sal_uInt16 GetSelectedAddress() const
bool IsSMTPAfterPOP() const
std::unique_ptr< SwAddressPreview_Impl > pImpl
void SAL_CALL first(const css::awt::SpinEvent &rEvent) override
virtual void SAL_CALL addAttachment(const css::mail::MailAttachment &aMailAttachment) override
bool CheckMailAddress(const OUString &rMailAddress)
constexpr sal_uInt16 KEY_LEFT
virtual ~SwConnectionListener() override
virtual void SAL_CALL setSubject(const OUString &_subject) override
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
OUString const & GetMailPassword() const
static OUString FillData(const OUString &rAddress, SwMailMergeConfigItem const &rConfigItem, const css::uno::Sequence< OUString > *pAssignments=nullptr)
const Color & GetWindowTextColor() const
void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
OUString const & GetMailUserName() const
sal_uInt16 nPos
virtual OUString SAL_CALL getPassword() override
sal_Int16 nValue
OUString const & GetInServerName() const
virtual css::uno::Sequence< css::mail::MailAttachment > SAL_CALL getAttachments() override