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 <sfx2/app.hxx>
27 #include <sfx2/fcontnr.hxx>
28 #include <com/sun/star/sdbc/SQLException.hpp>
29 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
30 #include <com/sun/star/sdb/XColumn.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
33 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
34 #include <com/sun/star/mail/MailServiceProvider.hpp>
35 #include <com/sun/star/mail/XSmtpService.hpp>
37 #include <vcl/event.hxx>
38 #include <vcl/settings.hxx>
39 #include <vcl/builderfactory.hxx>
40 #include <vcl/svapp.hxx>
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  OSL_FAIL("exception caught");
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  OSL_FAIL("SQLException caught");
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->set_user_managed_scrolling();
283  m_xVScrollBar->connect_vadjustment_changed(LINK(this, SwAddressPreview, ScrollHdl));
284 }
285 
287 {
288 }
289 
291 {
292  Invalidate();
293 }
294 
295 void SwAddressPreview::AddAddress(const OUString& rAddress)
296 {
297  pImpl->aAddresses.push_back(rAddress);
298  UpdateScrollBar();
299 }
300 
301 void SwAddressPreview::SetAddress(const OUString& rAddress)
302 {
303  pImpl->aAddresses.clear();
304  pImpl->aAddresses.push_back(rAddress);
305  m_xVScrollBar->set_vpolicy(VclPolicyType::NEVER);
306  Invalidate();
307 }
308 
310 {
311  OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAddresses.size(), "selection invalid");
312  return pImpl->nSelectedAddress;
313 }
314 
315 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
316 {
317  OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAddresses.size(), "selection invalid");
318  pImpl->nSelectedAddress = nSelect;
319  // now make it visible...
320  sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
321  sal_uInt16 nStartRow = m_xVScrollBar->vadjustment_get_value();
322  if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
323  m_xVScrollBar->vadjustment_set_value(nSelectRow);
324 }
325 
327 {
328  pImpl->aAddresses.clear();
329  pImpl->nSelectedAddress = 0;
330  UpdateScrollBar();
331 }
332 
334 {
335  pImpl->aAddresses[pImpl->nSelectedAddress] = rNew;
336  Invalidate();
337 }
338 
340 {
341  pImpl->aAddresses.erase(pImpl->aAddresses.begin() + pImpl->nSelectedAddress);
342  if(pImpl->nSelectedAddress)
343  --pImpl->nSelectedAddress;
344  UpdateScrollBar();
345  Invalidate();
346 }
347 
348 void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
349 {
350  pImpl->nRows = nRows;
351  pImpl->nColumns = nColumns;
352  UpdateScrollBar();
353 }
354 
356 {
357  pImpl->bEnableScrollBar = true;
358 }
359 
361 {
362  if (pImpl->nColumns)
363  {
364  sal_uInt16 nResultingRows = static_cast<sal_uInt16>(pImpl->aAddresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
365  ++nResultingRows;
366  auto nValue = m_xVScrollBar->vadjustment_get_value();
367  if (nValue > nResultingRows)
368  nValue = nResultingRows;
369  m_xVScrollBar->set_vpolicy(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows ? VclPolicyType::ALWAYS : VclPolicyType::NEVER);
370  m_xVScrollBar->vadjustment_configure(nValue, 0, nResultingRows, 1, 10, pImpl->nRows);
371  }
372 }
373 
375 {
376  const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
377  rRenderContext.SetFillColor(rSettings.GetWindowColor());
378  rRenderContext.SetLineColor(COL_TRANSPARENT);
379  rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), GetOutputSizePixel()));
380  Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
381  rRenderContext.SetLineColor(aPaintColor);
382 
383  if (vcl::Window* pDefaultDevice = dynamic_cast<vcl::Window*>(Application::GetDefaultDevice()))
384  pDefaultDevice->SetPointFont(rRenderContext, GetDrawingArea()->get_font());
385  vcl::Font aFont(rRenderContext.GetFont());
386  aFont.SetColor(aPaintColor);
387  rRenderContext.SetFont(aFont);
388 
389  Size aSize(GetOutputSizePixel());
390  sal_uInt16 nStartRow = 0;
391  if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER)
392  {
393  aSize.AdjustWidth(-m_xVScrollBar->get_vscroll_width());
394  nStartRow = m_xVScrollBar->vadjustment_get_value();
395  }
396  Size aPartSize(aSize.Width() / pImpl->nColumns,
397  aSize.Height() / pImpl->nRows);
398  aPartSize.AdjustWidth( -2 );
399  aPartSize.AdjustHeight( -2 );
400 
401  sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
402  const sal_uInt16 nNumAddresses = static_cast<sal_uInt16>(pImpl->aAddresses.size());
403  for (sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
404  {
405  for (sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
406  {
407  if (nAddress >= nNumAddresses)
408  break;
409  Point aPos(nCol * aPartSize.Width(),
410  nRow * aPartSize.Height());
411  aPos.Move(1, 1);
412  bool bIsSelected = nAddress == pImpl->nSelectedAddress;
413  if ((pImpl->nColumns * pImpl->nRows) == 1)
414  bIsSelected = false;
415  OUString adr(pImpl->aAddresses[nAddress]);
416  DrawText_Impl(rRenderContext, adr, aPos, aPartSize, bIsSelected);
417  ++nAddress;
418  }
419  }
420  rRenderContext.SetClipRegion();
421 }
422 
424 {
425  if (rMEvt.IsLeft() && pImpl->nRows && pImpl->nColumns)
426  {
427  //determine the selected address
428  const Point& rMousePos = rMEvt.GetPosPixel();
429  Size aSize(GetOutputSizePixel());
430  Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
431  sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
432  if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER)
433  {
434  nRow += m_xVScrollBar->vadjustment_get_value();
435  }
436  sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
437  sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
438 
439  if( nSelect < pImpl->aAddresses.size() &&
440  pImpl->nSelectedAddress != static_cast<sal_uInt16>(nSelect))
441  {
442  pImpl->nSelectedAddress = static_cast<sal_uInt16>(nSelect);
443  m_aSelectHdl.Call(nullptr);
444  }
445  Invalidate();
446  }
447  return true;
448 }
449 
451 {
452  sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
453  bool bHandled = false;
454  if (pImpl->nRows && pImpl->nColumns)
455  {
456  sal_uInt32 nSelectedRow = pImpl->nSelectedAddress / pImpl->nColumns;
457  sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress - (nSelectedRow * pImpl->nColumns);
458  switch(nKey)
459  {
460  case KEY_UP:
461  if(nSelectedRow)
462  --nSelectedRow;
463  bHandled = true;
464  break;
465  case KEY_DOWN:
466  if(pImpl->aAddresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
467  ++nSelectedRow;
468  bHandled = true;
469  break;
470  case KEY_LEFT:
471  if(nSelectedColumn)
472  --nSelectedColumn;
473  bHandled = true;
474  break;
475  case KEY_RIGHT:
476  if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
477  pImpl->aAddresses.size() - 1 > pImpl->nSelectedAddress )
478  ++nSelectedColumn;
479  bHandled = true;
480  break;
481  }
482  sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
483  if( nSelect < pImpl->aAddresses.size() &&
484  pImpl->nSelectedAddress != static_cast<sal_uInt16>(nSelect))
485  {
486  pImpl->nSelectedAddress = static_cast<sal_uInt16>(nSelect);
487  m_aSelectHdl.Call(nullptr);
488  Invalidate();
489  }
490  }
491  return bHandled;
492 }
493 
494 void SwAddressPreview::DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
495  const Point& rTopLeft, const Size& rSize, bool bIsSelected)
496 {
497  rRenderContext.SetClipRegion(vcl::Region(tools::Rectangle(rTopLeft, rSize)));
498  if (bIsSelected)
499  {
500  //selection rectangle
501  rRenderContext.SetFillColor(COL_TRANSPARENT);
502  rRenderContext.DrawRect(tools::Rectangle(rTopLeft, rSize));
503  }
504  sal_Int32 nHeight = GetTextHeight();
505  Point aStart = rTopLeft;
506  //put it away from the border
507  aStart.Move(2, 2);
508  sal_Int32 nPos = 0;
509  do
510  {
511  rRenderContext.DrawText(aStart, rAddress.getToken(0, '\n', nPos));
512  aStart.AdjustY(nHeight );
513  }
514  while (nPos >= 0);
515 }
516 
518 {
519  //currently the string may either start with a '<' then it's a column
520  //otherwise it's simple text maybe containing a return
521  SwMergeAddressItem aRet;
522  if(!sAddress.isEmpty())
523  {
524  if(sAddress[0] == '<')
525  {
526  aRet.bIsColumn = true;
527  sal_Int32 nClose = sAddress.indexOf('>');
528  OSL_ENSURE(nClose != -1, "closing '>' not found");
529  if( nClose != -1 )
530  {
531  aRet.sText = sAddress.copy(1, nClose - 1);
532  sAddress = sAddress.copy(nClose + 1);
533  }
534  else
535  {
536  aRet.sText = sAddress.copy(1, 1);
537  sAddress = sAddress.copy(1);
538  }
539  }
540  else
541  {
542  sal_Int32 nOpen = sAddress.indexOf('<');
543  sal_Int32 nReturn = sAddress.indexOf('\n');
544  if(nReturn == 0)
545  {
546  aRet.bIsReturn = true;
547  aRet.sText = "\n";
548  sAddress = sAddress.copy(1);
549  }
550  else if(-1 == nOpen && -1 == nReturn)
551  {
552  aRet.sText = sAddress;
553  sAddress.clear();
554  }
555  else
556  {
557  if (nOpen == -1)
558  nOpen = sAddress.getLength();
559  if (nReturn == -1)
560  nReturn = sAddress.getLength();
561  sal_Int32 nTarget = std::min(nOpen, nReturn);
562  aRet.sText = sAddress.copy(0, nTarget);
563  sAddress = sAddress.copy(nTarget);
564  }
565  }
566  }
567  return aRet;
568 
569 }
570 
572 {
573 }
574 
576 {
577  return m_aUserName;
578 }
579 
581 {
582  if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow)
583  {
585  aPasswdDlg.SetMinLen(0);
586  if (RET_OK == aPasswdDlg.run())
587  m_aPassword = aPasswdDlg.GetPassword();
588  }
589  return m_aPassword;
590 }
591 
593  const OUString& rMailServer, sal_Int16 nPort,
594  const OUString& rConnectionType) :
595  m_sMailServer(rMailServer),
596  m_nPort(nPort),
597  m_sConnectionType(rConnectionType)
598 {
599 }
600 
602 {
603 }
604 
606 {
607  uno::Any aRet;
608  if( rName == "ServerName" )
609  aRet <<= m_sMailServer;
610  else if( rName == "Port" )
611  aRet <<= static_cast<sal_Int32>(m_nPort);
612  else if( rName == "ConnectionType" )
613  aRet <<= m_sConnectionType;
614  return aRet;
615 }
616 
618 {
619 }
620 
621 void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
622 {
623 }
624 
625 void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
626 {
627 }
628 
629 void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
630 {
631 }
632 
633 SwMailTransferable::SwMailTransferable(const OUString& rBody, const OUString& rMimeType) :
634  cppu::WeakComponentImplHelper< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
635  m_aMimeType( rMimeType ),
636  m_sBody( rBody ),
637  m_bIsBody( true )
638 {
639 }
640 
642  const OUString& rName, const OUString& rMimeType) :
643  cppu::WeakComponentImplHelper< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
644  m_aMimeType( rMimeType ),
645  m_aURL(rURL),
646  m_aName( rName ),
647  m_bIsBody( false )
648 {
649 }
650 
652 {
653 }
654 
655 uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
656 {
657  uno::Any aRet;
658  if( m_bIsBody )
659  aRet <<= m_sBody;
660  else
661  {
663  SfxMedium aMedium( m_aURL, StreamMode::STD_READ );
664  SvStream* pStream = aMedium.GetInStream();
665  if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
666  {
667  aData.realloc(pStream->TellEnd());
668  pStream->Seek(0);
669  sal_Int8 * pData = aData.getArray();
670  pStream->ReadBytes( pData, aData.getLength() );
671  }
672  aRet <<= aData;
673  }
674  return aRet;
675 }
676 
677 uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
678 {
679  uno::Sequence< datatransfer::DataFlavor > aRet(1);
680  aRet[0].MimeType = m_aMimeType;
681  if( m_bIsBody )
682  {
683  aRet[0].DataType = cppu::UnoType<OUString>::get();
684  }
685  else
686  {
687  aRet[0].HumanPresentableName = m_aName;
688  aRet[0].DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get();
689  }
690  return aRet;
691 }
692 
694  const datatransfer::DataFlavor& aFlavor )
695 {
696  return (aFlavor.MimeType == m_aMimeType);
697 }
698 
699 uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( )
700 {
701  return uno::Reference< beans::XPropertySetInfo >();
702 }
703 
704 void SwMailTransferable::setPropertyValue( const OUString& , const uno::Any& )
705 {
706 }
707 
708 uno::Any SwMailTransferable::getPropertyValue( const OUString& rPropertyName )
709 {
710  uno::Any aRet;
711  if ( rPropertyName == "URL" )
712  aRet <<= m_aURL;
713  return aRet;
714 }
715 
717  const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
718 {
719 }
720 
722  const OUString&,
723  const uno::Reference< beans::XPropertyChangeListener >& )
724 {
725 }
726 
728  const OUString&,
729  const uno::Reference< beans::XVetoableChangeListener >& )
730 {
731 }
732 
734  const OUString& ,
735  const uno::Reference< beans::XVetoableChangeListener >& )
736 {
737 }
738 
740  cppu::WeakComponentImplHelper< mail::XMailMessage>(m_aMutex)
741 {
742 }
743 
745 {
746 }
747 
749 {
750  return m_sSenderName;
751 }
752 
754 {
755  return m_sSenderAddress;
756 }
757 
759 {
760  return m_sReplyToAddress;
761 }
762 
763 void SwMailMessage::setReplyToAddress( const OUString& _replytoaddress )
764 {
765  m_sReplyToAddress = _replytoaddress;
766 }
767 
769 {
770  return m_sSubject;
771 }
772 
773 void SwMailMessage::setSubject( const OUString& _subject )
774 {
775  m_sSubject = _subject;
776 }
777 
778 uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody()
779 {
780  return m_xBody;
781 }
782 
784  const uno::Reference< datatransfer::XTransferable >& rBody )
785 {
786  m_xBody = rBody;
787 }
788 
789 void SwMailMessage::addRecipient( const OUString& rRecipientAddress )
790 {
791  m_aRecipients.realloc(m_aRecipients.getLength() + 1);
792  m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
793 }
794 
795 void SwMailMessage::addCcRecipient( const OUString& rRecipientAddress )
796 {
797  m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
798  m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
799 
800 }
801 
802 void SwMailMessage::addBccRecipient( const OUString& rRecipientAddress )
803 {
804  m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
805  m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
806 }
807 
808 uno::Sequence< OUString > SwMailMessage::getRecipients( )
809 {
810  return m_aRecipients;
811 }
812 
813 uno::Sequence< OUString > SwMailMessage::getCcRecipients( )
814 {
815  return m_aCcRecipients;
816 }
817 
818 uno::Sequence< OUString > SwMailMessage::getBccRecipients( )
819 {
820  return m_aBccRecipients;
821 }
822 
823 void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
824 {
825  m_aAttachments.realloc(m_aAttachments.getLength() + 1);
826  m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
827 }
828 
829 uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
830 {
831  return m_aAttachments;
832 }
833 
834 /* 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
OUString const m_sConnectionType
virtual void SAL_CALL setBody(const css::uno::Reference< css::datatransfer::XTransferable > &_body) override
::osl::Mutex m_aMutex
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)
long AdjustWidth(long n)
virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor &aFlavor) override
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
OUString const m_aURL
css::uno::Reference< css::datatransfer::XTransferable > m_xBody
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)
#define KEY_LEFT
Size const & GetOutputSizePixel() const
OUString const m_sBody
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
sal_Int16 const m_nPort
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
OUString const m_aName
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
sal_Int16 GetInServerPort() const
css::uno::Reference< css::sdbc::XResultSet > const & GetResultSet() const
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)
long AdjustY(long nVertMove)
IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl, weld::ScrolledWindow &, void)
class SAL_NO_VTABLE XPropertySet
virtual OUString SAL_CALL getUserName() override
OUString m_sSenderAddress
void SetFillColor()
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
GUIDCNamePair const aData
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
virtual css::uno::Sequence< OUString > SAL_CALL getRecipients() override
virtual ~SwMailMessage() override
bool IsInServerPOP() const
long X() 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
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 m_sMailServer
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
#define KEY_DOWN
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 &)
OUString const m_aMimeType
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
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
void Move(long nHorzMove, long nVertMove)
bool CheckMailAddress(const OUString &rMailAddress)
OUString const m_aUserName
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
sal_Int32 nPos
static OUString FillData(const OUString &rAddress, SwMailMergeConfigItem const &rConfigItem, const css::uno::Sequence< OUString > *pAssignments=nullptr)
const Color & GetWindowTextColor() const
#define KEY_RIGHT
void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
OUString const & GetMailUserName() const
long Y() const
virtual OUString SAL_CALL getPassword() override
OUString const & GetInServerName() const
virtual css::uno::Sequence< css::mail::MailAttachment > SAL_CALL getAttachments() override
#define KEY_UP