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 #include <vcl/weldutils.hxx>
40 #include <tools/diagnose_ex.h>
41 
42 #include <sfx2/passwd.hxx>
43 
44 #include <dbui.hrc>
45 #include <strings.hrc>
46 
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::container;
50 using namespace ::com::sun::star::sdb;
51 using namespace ::com::sun::star::sdbc;
52 using namespace ::com::sun::star::sdbcx;
53 
55 {
56 
57 OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter)
58 {
59  ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
60  FileDialogFlags::NONE,
61  SwDocShell::Factory().GetFactoryName(), SfxFilterFlags::NONE, SfxFilterFlags::NONE, pParent);
62 
63  if (aDialog.Execute()!=ERRCODE_NONE)
64  {
65  return OUString();
66  }
67 
68  rFilter = aDialog.GetRealFilter();
69  uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDialog.GetFilePicker();
70  return xFP->getSelectedFiles().getConstArray()[0];
71 }
72 
73 /*
74  simple address check: check for '@'
75  for at least one '.' after the '@'
76  and for at least two characters before and after the dot
77 */
78 bool CheckMailAddress( const OUString& rMailAddress )
79 {
80  const sal_Int32 nPosAt = rMailAddress.indexOf('@');
81  if (nPosAt<0 || rMailAddress.lastIndexOf('@')!=nPosAt)
82  return false;
83  const sal_Int32 nPosDot = rMailAddress.indexOf('.', nPosAt);
84  return !(nPosDot<0 || nPosDot-nPosAt<3 || rMailAddress.getLength()-nPosDot<3);
85 }
86 
87 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
88  SwMailMergeConfigItem const & rConfigItem,
89  uno::Reference< mail::XMailService >& rxInMailService,
90  const OUString& rInMailServerPassword,
91  const OUString& rOutMailServerPassword,
92  weld::Window* pDialogParentWindow )
93 {
94  uno::Reference< mail::XSmtpService > xSmtpServer;
95  uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
96  try
97  {
98  uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
99  mail::MailServiceProvider::create( xContext ) );
100  xSmtpServer.set(xMailServiceProvider->create(mail::MailServiceType_SMTP), uno::UNO_QUERY);
101 
102  uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
103 
104  if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
105  {
106  uno::Reference< mail::XMailService > xInMailService =
107  xMailServiceProvider->create(
108  rConfigItem.IsInServerPOP() ?
109  mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
110  //authenticate at the POP or IMAP server first
111  OUString sPasswd = rConfigItem.GetInServerPassword();
112  if(!rInMailServerPassword.isEmpty())
113  sPasswd = rInMailServerPassword;
114  uno::Reference<mail::XAuthenticator> xAuthenticator =
115  new SwAuthenticator(
116  rConfigItem.GetInServerUserName(),
117  sPasswd,
118  pDialogParentWindow);
119 
120  xInMailService->addConnectionListener(xConnectionListener);
121  //check connection
122  uno::Reference< uno::XCurrentContext> xConnectionContext =
124  rConfigItem.GetInServerName(),
125  rConfigItem.GetInServerPort(),
126  "Insecure");
127  xInMailService->connect(xConnectionContext, xAuthenticator);
128  rxInMailService = xInMailService;
129  }
130  uno::Reference< mail::XAuthenticator> xAuthenticator;
131  if(rConfigItem.IsAuthentication() &&
132  !rConfigItem.IsSMTPAfterPOP() &&
133  !rConfigItem.GetMailUserName().isEmpty())
134  {
135  OUString sPasswd = rConfigItem.GetMailPassword();
136  if(!rOutMailServerPassword.isEmpty())
137  sPasswd = rOutMailServerPassword;
138  xAuthenticator =
139  new SwAuthenticator(rConfigItem.GetMailUserName(),
140  sPasswd,
141  pDialogParentWindow);
142  }
143  else
144  xAuthenticator = new SwAuthenticator();
145  //just to check if the server exists
146  xSmtpServer->getSupportedConnectionTypes();
147  //check connection
148 
149  uno::Reference< uno::XCurrentContext> xConnectionContext =
151  rConfigItem.GetMailServer(),
152  rConfigItem.GetMailPort(),
153  rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
154  xSmtpServer->connect(xConnectionContext, xAuthenticator);
155  rxInMailService = xSmtpServer;
156  }
157  catch (const uno::Exception&)
158  {
159  TOOLS_WARN_EXCEPTION( "sw", "");
160  }
161  return xSmtpServer;
162 }
163 
164 } //namespace
165 
167 {
168  std::vector< OUString > aAddresses;
169  sal_uInt16 nRows;
170  sal_uInt16 nColumns;
171  sal_uInt16 nSelectedAddress;
173 
175  nRows(1),
176  nColumns(1),
177  nSelectedAddress(0),
178  bEnableScrollBar(false)
179  {
180  }
181 };
182 
184  const OUString& rAddress,
185  SwMailMergeConfigItem const & rConfigItem,
186  const Sequence< OUString>* pAssignments)
187 {
188  //find the column names in the address string (with name assignment!) and
189  //exchange the placeholder (like <Firstname>) with the database content
190  //unassigned columns are expanded to <not assigned>
191  Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
192  Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
193  Sequence< OUString> aAssignment = pAssignments ?
194  *pAssignments :
195  rConfigItem.GetColumnAssignment(
196  rConfigItem.GetCurrentDBData() );
197  const OUString* pAssignment = aAssignment.getConstArray();
198  const std::vector<std::pair<OUString, int>>& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
199  OUString sNotAssigned = "<" + SwResId(STR_NOTASSIGNED) + ">";
200 
201  bool bIncludeCountry = rConfigItem.IsIncludeCountry();
202  const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
203  bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
204  OUString sCountryColumn;
205  if( bSpecialReplacementForCountry )
206  {
207  sCountryColumn = rDefHeaders[MM_PART_COUNTRY].first;
208  Sequence< OUString> aSpecialAssignment =
209  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
210  if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
211  sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
212  }
213 
214  SwAddressIterator aIter(rAddress);
215  OUStringBuffer sAddress;
216  while(aIter.HasMore())
217  {
218  SwMergeAddressItem aItem = aIter.Next();
219  if(aItem.bIsColumn)
220  {
221  //get the default column name
222 
223  //find the appropriate assignment
224  OUString sConvertedColumn = aItem.sText;
225  auto nSize = std::min(sal_uInt32(rDefHeaders.size()), sal_uInt32(aAssignment.getLength()));
226  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
227  {
228  if (rDefHeaders[nColumn].first == aItem.sText &&
229  !pAssignment[nColumn].isEmpty())
230  {
231  sConvertedColumn = pAssignment[nColumn];
232  break;
233  }
234  }
235  if(!sConvertedColumn.isEmpty() &&
236  xColAccess.is() &&
237  xColAccess->hasByName(sConvertedColumn))
238  {
239  //get the content and exchange it in the address string
240  Any aCol = xColAccess->getByName(sConvertedColumn);
241  Reference< XColumn > xColumn;
242  aCol >>= xColumn;
243  if(xColumn.is())
244  {
245  try
246  {
247  OUString sReplace = xColumn->getString();
248 
249  if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
250  {
251  if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
252  aItem.sText = sReplace;
253  else
254  aItem.sText.clear();
255  }
256  else
257  {
258  aItem.sText = sReplace;
259  }
260  }
261  catch (const sdbc::SQLException&)
262  {
263  TOOLS_WARN_EXCEPTION( "sw", "");
264  }
265  }
266  }
267  else
268  {
269  aItem.sText = sNotAssigned;
270  }
271 
272  }
273  sAddress.append(aItem.sText);
274  }
275  return sAddress.makeStringAndClear();
276 }
277 
278 SwAddressPreview::SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xWindow)
279  : pImpl(new SwAddressPreview_Impl())
280  , m_xVScrollBar(std::move(xWindow))
281 {
282  m_xVScrollBar->connect_vadjustment_changed(LINK(this, SwAddressPreview, ScrollHdl));
283 }
284 
286 {
287 }
288 
290 {
291  Invalidate();
292 }
293 
294 void SwAddressPreview::AddAddress(const OUString& rAddress)
295 {
296  pImpl->aAddresses.push_back(rAddress);
297  UpdateScrollBar();
298 }
299 
300 void SwAddressPreview::SetAddress(const OUString& rAddress)
301 {
302  pImpl->aAddresses.clear();
303  pImpl->aAddresses.push_back(rAddress);
304  m_xVScrollBar->set_vpolicy(VclPolicyType::NEVER);
305  Invalidate();
306 }
307 
309 {
310  OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAddresses.size(), "selection invalid");
311  return pImpl->nSelectedAddress;
312 }
313 
314 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
315 {
316  OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAddresses.size(), "selection invalid");
317  pImpl->nSelectedAddress = nSelect;
318  // now make it visible...
319  sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
320  sal_uInt16 nStartRow = m_xVScrollBar->vadjustment_get_value();
321  if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
322  m_xVScrollBar->vadjustment_set_value(nSelectRow);
323 }
324 
326 {
327  pImpl->aAddresses.clear();
328  pImpl->nSelectedAddress = 0;
329  UpdateScrollBar();
330 }
331 
333 {
334  pImpl->aAddresses[pImpl->nSelectedAddress] = rNew;
335  Invalidate();
336 }
337 
339 {
340  pImpl->aAddresses.erase(pImpl->aAddresses.begin() + pImpl->nSelectedAddress);
341  if(pImpl->nSelectedAddress)
342  --pImpl->nSelectedAddress;
343  UpdateScrollBar();
344  Invalidate();
345 }
346 
347 void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
348 {
349  pImpl->nRows = nRows;
350  pImpl->nColumns = nColumns;
351  UpdateScrollBar();
352 }
353 
355 {
356  pImpl->bEnableScrollBar = true;
357 }
358 
360 {
361  if (pImpl->nColumns)
362  {
363  sal_uInt16 nResultingRows = static_cast<sal_uInt16>(pImpl->aAddresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
364  ++nResultingRows;
365  auto nValue = m_xVScrollBar->vadjustment_get_value();
366  if (nValue > nResultingRows)
367  nValue = nResultingRows;
368  m_xVScrollBar->set_vpolicy(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows ? VclPolicyType::ALWAYS : VclPolicyType::NEVER);
369  m_xVScrollBar->vadjustment_configure(nValue, 0, nResultingRows, 1, 10, pImpl->nRows);
370  }
371 }
372 
374 {
375  const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
376  rRenderContext.SetFillColor(rSettings.GetWindowColor());
377  rRenderContext.SetLineColor(COL_TRANSPARENT);
378  rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), GetOutputSizePixel()));
379  Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
380  rRenderContext.SetLineColor(aPaintColor);
381 
382  weld::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_scroll_thickness());
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()
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
exports com.sun.star. mail
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
OUString m_aName
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)
signed char sal_Int8
bool IsSecureConnection() const
css::uno::Sequence< OUString > m_aCcRecipients
virtual sal_uInt64 TellEnd()
OUString & GetExcludeCountry() const
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
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)
constexpr tools::Long Width() const
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
constexpr OUStringLiteral aData
Definition: ww8scan.hxx:47
sal_Int16 GetInServerPort() const
css::uno::Reference< css::sdbc::XResultSet > const & GetResultSet() const
constexpr sal_uInt16 KEY_DOWN
exports com.sun.star. datatransfer
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
#define TOOLS_WARN_EXCEPTION(area, stream)
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:166
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
exports com.sun.star. beans
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
constexpr tools::Long Height() const
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
tools::Long AdjustWidth(tools::Long n)
virtual void SAL_CALL setReplyToAddress(const OUString &_replytoaddress) override
void SetPointFont(OutputDevice &rDevice, const vcl::Font &rFont)
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
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
constexpr OUStringLiteral first
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