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/svapp.hxx>
40 
41 #include <sfx2/passwd.hxx>
42 
43 #include <dbui.hrc>
44 #include <strings.hrc>
45 
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::sdb;
50 using namespace ::com::sun::star::sdbc;
51 using namespace ::com::sun::star::sdbcx;
52 
54 {
55 
56 OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter)
57 {
58  ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
59  FileDialogFlags::NONE,
60  SwDocShell::Factory().GetFactoryName(), SfxFilterFlags::NONE, SfxFilterFlags::NONE, pParent);
61 
62  if (aDialog.Execute()!=ERRCODE_NONE)
63  {
64  return OUString();
65  }
66 
67  rFilter = aDialog.GetRealFilter();
68  uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDialog.GetFilePicker();
69  return xFP->getSelectedFiles().getConstArray()[0];
70 }
71 
72 /*
73  simple address check: check for '@'
74  for at least one '.' after the '@'
75  and for at least two characters before and after the dot
76 */
77 bool CheckMailAddress( const OUString& rMailAddress )
78 {
79  const sal_Int32 nPosAt = rMailAddress.indexOf('@');
80  if (nPosAt<0 || rMailAddress.lastIndexOf('@')!=nPosAt)
81  return false;
82  const sal_Int32 nPosDot = rMailAddress.indexOf('.', nPosAt);
83  return !(nPosDot<0 || nPosDot-nPosAt<3 || rMailAddress.getLength()-nPosDot<3);
84 }
85 
86 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
87  SwMailMergeConfigItem const & rConfigItem,
88  uno::Reference< mail::XMailService >& rxInMailService,
89  const OUString& rInMailServerPassword,
90  const OUString& rOutMailServerPassword,
91  weld::Window* pDialogParentWindow )
92 {
93  uno::Reference< mail::XSmtpService > xSmtpServer;
94  uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
95  try
96  {
97  uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
98  mail::MailServiceProvider::create( xContext ) );
99  xSmtpServer.set(xMailServiceProvider->create(mail::MailServiceType_SMTP), uno::UNO_QUERY);
100 
101  uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
102 
103  if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
104  {
105  uno::Reference< mail::XMailService > xInMailService =
106  xMailServiceProvider->create(
107  rConfigItem.IsInServerPOP() ?
108  mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
109  //authenticate at the POP or IMAP server first
110  OUString sPasswd = rConfigItem.GetInServerPassword();
111  if(!rInMailServerPassword.isEmpty())
112  sPasswd = rInMailServerPassword;
113  uno::Reference<mail::XAuthenticator> xAuthenticator =
114  new SwAuthenticator(
115  rConfigItem.GetInServerUserName(),
116  sPasswd,
117  pDialogParentWindow);
118 
119  xInMailService->addConnectionListener(xConnectionListener);
120  //check connection
121  uno::Reference< uno::XCurrentContext> xConnectionContext =
123  rConfigItem.GetInServerName(),
124  rConfigItem.GetInServerPort(),
125  "Insecure");
126  xInMailService->connect(xConnectionContext, xAuthenticator);
127  rxInMailService = xInMailService;
128  }
129  uno::Reference< mail::XAuthenticator> xAuthenticator;
130  if(rConfigItem.IsAuthentication() &&
131  !rConfigItem.IsSMTPAfterPOP() &&
132  !rConfigItem.GetMailUserName().isEmpty())
133  {
134  OUString sPasswd = rConfigItem.GetMailPassword();
135  if(!rOutMailServerPassword.isEmpty())
136  sPasswd = rOutMailServerPassword;
137  xAuthenticator =
138  new SwAuthenticator(rConfigItem.GetMailUserName(),
139  sPasswd,
140  pDialogParentWindow);
141  }
142  else
143  xAuthenticator = new SwAuthenticator();
144  //just to check if the server exists
145  xSmtpServer->getSupportedConnectionTypes();
146  //check connection
147 
148  uno::Reference< uno::XCurrentContext> xConnectionContext =
150  rConfigItem.GetMailServer(),
151  rConfigItem.GetMailPort(),
152  rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
153  xSmtpServer->connect(xConnectionContext, xAuthenticator);
154  rxInMailService = xSmtpServer;
155  }
156  catch (const uno::Exception&)
157  {
158  OSL_FAIL("exception caught");
159  }
160  return xSmtpServer;
161 }
162 
163 } //namespace
164 
166 {
167  std::vector< OUString > aAddresses;
168  sal_uInt16 nRows;
169  sal_uInt16 nColumns;
170  sal_uInt16 nSelectedAddress;
172 
174  nRows(1),
175  nColumns(1),
176  nSelectedAddress(0),
177  bEnableScrollBar(false)
178  {
179  }
180 };
181 
183  const OUString& rAddress,
184  SwMailMergeConfigItem const & rConfigItem,
185  const Sequence< OUString>* pAssignments)
186 {
187  //find the column names in the address string (with name assignment!) and
188  //exchange the placeholder (like <Firstname>) with the database content
189  //unassigned columns are expanded to <not assigned>
190  Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
191  Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
192  Sequence< OUString> aAssignment = pAssignments ?
193  *pAssignments :
194  rConfigItem.GetColumnAssignment(
195  rConfigItem.GetCurrentDBData() );
196  const OUString* pAssignment = aAssignment.getConstArray();
197  const std::vector<std::pair<OUString, int>>& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
198  OUString sNotAssigned = "<" + SwResId(STR_NOTASSIGNED) + ">";
199 
200  bool bIncludeCountry = rConfigItem.IsIncludeCountry();
201  const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
202  bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
203  OUString sCountryColumn;
204  if( bSpecialReplacementForCountry )
205  {
206  sCountryColumn = rDefHeaders[MM_PART_COUNTRY].first;
207  Sequence< OUString> aSpecialAssignment =
208  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
209  if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
210  sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
211  }
212 
213  SwAddressIterator aIter(rAddress);
214  OUStringBuffer sAddress;
215  while(aIter.HasMore())
216  {
217  SwMergeAddressItem aItem = aIter.Next();
218  if(aItem.bIsColumn)
219  {
220  //get the default column name
221 
222  //find the appropriate assignment
223  OUString sConvertedColumn = aItem.sText;
224  auto nSize = std::min(sal_uInt32(rDefHeaders.size()), sal_uInt32(aAssignment.getLength()));
225  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
226  {
227  if (rDefHeaders[nColumn].first == aItem.sText &&
228  !pAssignment[nColumn].isEmpty())
229  {
230  sConvertedColumn = pAssignment[nColumn];
231  break;
232  }
233  }
234  if(!sConvertedColumn.isEmpty() &&
235  xColAccess.is() &&
236  xColAccess->hasByName(sConvertedColumn))
237  {
238  //get the content and exchange it in the address string
239  Any aCol = xColAccess->getByName(sConvertedColumn);
240  Reference< XColumn > xColumn;
241  aCol >>= xColumn;
242  if(xColumn.is())
243  {
244  try
245  {
246  OUString sReplace = xColumn->getString();
247 
248  if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
249  {
250  if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
251  aItem.sText = sReplace;
252  else
253  aItem.sText.clear();
254  }
255  else
256  {
257  aItem.sText = sReplace;
258  }
259  }
260  catch (const sdbc::SQLException&)
261  {
262  OSL_FAIL("SQLException caught");
263  }
264  }
265  }
266  else
267  {
268  aItem.sText = sNotAssigned;
269  }
270 
271  }
272  sAddress.append(aItem.sText);
273  }
274  return sAddress.makeStringAndClear();
275 }
276 
277 SwAddressPreview::SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xWindow)
278  : pImpl(new SwAddressPreview_Impl())
279  , m_xVScrollBar(std::move(xWindow))
280 {
281  m_xVScrollBar->set_user_managed_scrolling();
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  if (vcl::Window* pDefaultDevice = dynamic_cast<vcl::Window*>(Application::GetDefaultDevice()))
383  pDefaultDevice->SetPointFont(rRenderContext, GetDrawingArea()->get_font());
384  vcl::Font aFont(rRenderContext.GetFont());
385  aFont.SetColor(aPaintColor);
386  rRenderContext.SetFont(aFont);
387 
388  Size aSize(GetOutputSizePixel());
389  sal_uInt16 nStartRow = 0;
390  if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER)
391  {
392  aSize.AdjustWidth(-m_xVScrollBar->get_vscroll_width());
393  nStartRow = m_xVScrollBar->vadjustment_get_value();
394  }
395  Size aPartSize(aSize.Width() / pImpl->nColumns,
396  aSize.Height() / pImpl->nRows);
397  aPartSize.AdjustWidth( -2 );
398  aPartSize.AdjustHeight( -2 );
399 
400  sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
401  const sal_uInt16 nNumAddresses = static_cast<sal_uInt16>(pImpl->aAddresses.size());
402  for (sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
403  {
404  for (sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
405  {
406  if (nAddress >= nNumAddresses)
407  break;
408  Point aPos(nCol * aPartSize.Width(),
409  nRow * aPartSize.Height());
410  aPos.Move(1, 1);
411  bool bIsSelected = nAddress == pImpl->nSelectedAddress;
412  if ((pImpl->nColumns * pImpl->nRows) == 1)
413  bIsSelected = false;
414  OUString adr(pImpl->aAddresses[nAddress]);
415  DrawText_Impl(rRenderContext, adr, aPos, aPartSize, bIsSelected);
416  ++nAddress;
417  }
418  }
419  rRenderContext.SetClipRegion();
420 }
421 
423 {
424  if (rMEvt.IsLeft() && pImpl->nRows && pImpl->nColumns)
425  {
426  //determine the selected address
427  const Point& rMousePos = rMEvt.GetPosPixel();
428  Size aSize(GetOutputSizePixel());
429  Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
430  sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
431  if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER)
432  {
433  nRow += m_xVScrollBar->vadjustment_get_value();
434  }
435  sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
436  sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
437 
438  if( nSelect < pImpl->aAddresses.size() &&
439  pImpl->nSelectedAddress != static_cast<sal_uInt16>(nSelect))
440  {
441  pImpl->nSelectedAddress = static_cast<sal_uInt16>(nSelect);
442  m_aSelectHdl.Call(nullptr);
443  }
444  Invalidate();
445  }
446  return true;
447 }
448 
450 {
451  sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
452  bool bHandled = false;
453  if (pImpl->nRows && pImpl->nColumns)
454  {
455  sal_uInt32 nSelectedRow = pImpl->nSelectedAddress / pImpl->nColumns;
456  sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress - (nSelectedRow * pImpl->nColumns);
457  switch(nKey)
458  {
459  case KEY_UP:
460  if(nSelectedRow)
461  --nSelectedRow;
462  bHandled = true;
463  break;
464  case KEY_DOWN:
465  if(pImpl->aAddresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
466  ++nSelectedRow;
467  bHandled = true;
468  break;
469  case KEY_LEFT:
470  if(nSelectedColumn)
471  --nSelectedColumn;
472  bHandled = true;
473  break;
474  case KEY_RIGHT:
475  if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
476  pImpl->aAddresses.size() - 1 > pImpl->nSelectedAddress )
477  ++nSelectedColumn;
478  bHandled = true;
479  break;
480  }
481  sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
482  if( nSelect < pImpl->aAddresses.size() &&
483  pImpl->nSelectedAddress != static_cast<sal_uInt16>(nSelect))
484  {
485  pImpl->nSelectedAddress = static_cast<sal_uInt16>(nSelect);
486  m_aSelectHdl.Call(nullptr);
487  Invalidate();
488  }
489  }
490  return bHandled;
491 }
492 
493 void SwAddressPreview::DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
494  const Point& rTopLeft, const Size& rSize, bool bIsSelected)
495 {
496  rRenderContext.SetClipRegion(vcl::Region(tools::Rectangle(rTopLeft, rSize)));
497  if (bIsSelected)
498  {
499  //selection rectangle
500  rRenderContext.SetFillColor(COL_TRANSPARENT);
501  rRenderContext.DrawRect(tools::Rectangle(rTopLeft, rSize));
502  }
503  sal_Int32 nHeight = GetTextHeight();
504  Point aStart = rTopLeft;
505  //put it away from the border
506  aStart.Move(2, 2);
507  sal_Int32 nPos = 0;
508  do
509  {
510  rRenderContext.DrawText(aStart, rAddress.getToken(0, '\n', nPos));
511  aStart.AdjustY(nHeight );
512  }
513  while (nPos >= 0);
514 }
515 
517 {
518  //currently the string may either start with a '<' then it's a column
519  //otherwise it's simple text maybe containing a return
520  SwMergeAddressItem aRet;
521  if(!sAddress.isEmpty())
522  {
523  if(sAddress[0] == '<')
524  {
525  aRet.bIsColumn = true;
526  sal_Int32 nClose = sAddress.indexOf('>');
527  OSL_ENSURE(nClose != -1, "closing '>' not found");
528  if( nClose != -1 )
529  {
530  aRet.sText = sAddress.copy(1, nClose - 1);
531  sAddress = sAddress.copy(nClose + 1);
532  }
533  else
534  {
535  aRet.sText = sAddress.copy(1, 1);
536  sAddress = sAddress.copy(1);
537  }
538  }
539  else
540  {
541  sal_Int32 nOpen = sAddress.indexOf('<');
542  sal_Int32 nReturn = sAddress.indexOf('\n');
543  if(nReturn == 0)
544  {
545  aRet.bIsReturn = true;
546  aRet.sText = "\n";
547  sAddress = sAddress.copy(1);
548  }
549  else if(-1 == nOpen && -1 == nReturn)
550  {
551  aRet.sText = sAddress;
552  sAddress.clear();
553  }
554  else
555  {
556  if (nOpen == -1)
557  nOpen = sAddress.getLength();
558  if (nReturn == -1)
559  nReturn = sAddress.getLength();
560  sal_Int32 nTarget = std::min(nOpen, nReturn);
561  aRet.sText = sAddress.copy(0, nTarget);
562  sAddress = sAddress.copy(nTarget);
563  }
564  }
565  }
566  return aRet;
567 
568 }
569 
571 {
572 }
573 
575 {
576  return m_aUserName;
577 }
578 
580 {
581  if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow)
582  {
584  aPasswdDlg.SetMinLen(0);
585  if (RET_OK == aPasswdDlg.run())
586  m_aPassword = aPasswdDlg.GetPassword();
587  }
588  return m_aPassword;
589 }
590 
592  const OUString& rMailServer, sal_Int16 nPort,
593  const OUString& rConnectionType) :
594  m_sMailServer(rMailServer),
595  m_nPort(nPort),
596  m_sConnectionType(rConnectionType)
597 {
598 }
599 
601 {
602 }
603 
605 {
606  uno::Any aRet;
607  if( rName == "ServerName" )
608  aRet <<= m_sMailServer;
609  else if( rName == "Port" )
610  aRet <<= static_cast<sal_Int32>(m_nPort);
611  else if( rName == "ConnectionType" )
612  aRet <<= m_sConnectionType;
613  return aRet;
614 }
615 
617 {
618 }
619 
620 void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
621 {
622 }
623 
624 void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
625 {
626 }
627 
628 void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
629 {
630 }
631 
632 SwMailTransferable::SwMailTransferable(const OUString& rBody, const OUString& rMimeType) :
633  cppu::WeakComponentImplHelper< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
634  m_aMimeType( rMimeType ),
635  m_sBody( rBody ),
636  m_bIsBody( true )
637 {
638 }
639 
641  const OUString& rName, const OUString& rMimeType) :
642  cppu::WeakComponentImplHelper< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
643  m_aMimeType( rMimeType ),
644  m_aURL(rURL),
645  m_aName( rName ),
646  m_bIsBody( false )
647 {
648 }
649 
651 {
652 }
653 
654 uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
655 {
656  uno::Any aRet;
657  if( m_bIsBody )
658  aRet <<= m_sBody;
659  else
660  {
662  SfxMedium aMedium( m_aURL, StreamMode::STD_READ );
663  SvStream* pStream = aMedium.GetInStream();
664  if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
665  {
666  aData.realloc(pStream->TellEnd());
667  pStream->Seek(0);
668  sal_Int8 * pData = aData.getArray();
669  pStream->ReadBytes( pData, aData.getLength() );
670  }
671  aRet <<= aData;
672  }
673  return aRet;
674 }
675 
676 uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
677 {
678  uno::Sequence< datatransfer::DataFlavor > aRet(1);
679  aRet[0].MimeType = m_aMimeType;
680  if( m_bIsBody )
681  {
682  aRet[0].DataType = cppu::UnoType<OUString>::get();
683  }
684  else
685  {
686  aRet[0].HumanPresentableName = m_aName;
687  aRet[0].DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get();
688  }
689  return aRet;
690 }
691 
693  const datatransfer::DataFlavor& aFlavor )
694 {
695  return (aFlavor.MimeType == m_aMimeType);
696 }
697 
698 uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( )
699 {
700  return uno::Reference< beans::XPropertySetInfo >();
701 }
702 
703 void SwMailTransferable::setPropertyValue( const OUString& , const uno::Any& )
704 {
705 }
706 
707 uno::Any SwMailTransferable::getPropertyValue( const OUString& rPropertyName )
708 {
709  uno::Any aRet;
710  if ( rPropertyName == "URL" )
711  aRet <<= m_aURL;
712  return aRet;
713 }
714 
716  const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
717 {
718 }
719 
721  const OUString&,
722  const uno::Reference< beans::XPropertyChangeListener >& )
723 {
724 }
725 
727  const OUString&,
728  const uno::Reference< beans::XVetoableChangeListener >& )
729 {
730 }
731 
733  const OUString& ,
734  const uno::Reference< beans::XVetoableChangeListener >& )
735 {
736 }
737 
739  cppu::WeakComponentImplHelper< mail::XMailMessage>(m_aMutex)
740 {
741 }
742 
744 {
745 }
746 
748 {
749  return m_sSenderName;
750 }
751 
753 {
754  return m_sSenderAddress;
755 }
756 
758 {
759  return m_sReplyToAddress;
760 }
761 
762 void SwMailMessage::setReplyToAddress( const OUString& _replytoaddress )
763 {
764  m_sReplyToAddress = _replytoaddress;
765 }
766 
768 {
769  return m_sSubject;
770 }
771 
772 void SwMailMessage::setSubject( const OUString& _subject )
773 {
774  m_sSubject = _subject;
775 }
776 
777 uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody()
778 {
779  return m_xBody;
780 }
781 
783  const uno::Reference< datatransfer::XTransferable >& rBody )
784 {
785  m_xBody = rBody;
786 }
787 
788 void SwMailMessage::addRecipient( const OUString& rRecipientAddress )
789 {
790  m_aRecipients.realloc(m_aRecipients.getLength() + 1);
791  m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
792 }
793 
794 void SwMailMessage::addCcRecipient( const OUString& rRecipientAddress )
795 {
796  m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
797  m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
798 
799 }
800 
801 void SwMailMessage::addBccRecipient( const OUString& rRecipientAddress )
802 {
803  m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
804  m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
805 }
806 
807 uno::Sequence< OUString > SwMailMessage::getRecipients( )
808 {
809  return m_aRecipients;
810 }
811 
812 uno::Sequence< OUString > SwMailMessage::getCcRecipients( )
813 {
814  return m_aCcRecipients;
815 }
816 
817 uno::Sequence< OUString > SwMailMessage::getBccRecipients( )
818 {
819  return m_aBccRecipients;
820 }
821 
822 void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
823 {
824  m_aAttachments.realloc(m_aAttachments.getLength() + 1);
825  m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
826 }
827 
828 uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
829 {
830  return m_aAttachments;
831 }
832 
833 /* 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:190
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