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