LibreOffice Module sw (master)  1
mailmergehelper.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <swtypes.hxx>
21 #include <mailmergehelper.hxx>
22 #include <mmconfigitem.hxx>
23 #include <docsh.hxx>
24 #include <sfx2/filedlghelper.hxx>
25 #include <sfx2/docfile.hxx>
26 #include <com/sun/star/sdbc/SQLException.hpp>
27 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28 #include <com/sun/star/sdb/XColumn.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
31 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
32 #include <com/sun/star/mail/MailServiceProvider.hpp>
33 #include <com/sun/star/mail/XSmtpService.hpp>
35 #include <o3tl/safeint.hxx>
36 #include <vcl/event.hxx>
37 #include <vcl/settings.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/weldutils.hxx>
40 #include <tools/diagnose_ex.h>
41 
42 #include <sfx2/passwd.hxx>
43 
44 #include <dbui.hrc>
45 #include <strings.hrc>
46 
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::container;
50 using namespace ::com::sun::star::sdb;
51 using namespace ::com::sun::star::sdbc;
52 using namespace ::com::sun::star::sdbcx;
53 
55 {
56 
57 OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter)
58 {
59  ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
60  FileDialogFlags::NONE,
61  SwDocShell::Factory().GetFactoryName(), SfxFilterFlags::NONE, SfxFilterFlags::NONE, pParent);
63 
64  if (aDialog.Execute()!=ERRCODE_NONE)
65  {
66  return OUString();
67  }
68 
69  rFilter = aDialog.GetRealFilter();
70  uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDialog.GetFilePicker();
71  return xFP->getSelectedFiles().getConstArray()[0];
72 }
73 
74 /*
75  simple address check: check for '@'
76  for at least one '.' after the '@'
77  and for at least two characters before and after the dot
78 */
79 bool CheckMailAddress( const OUString& rMailAddress )
80 {
81  const sal_Int32 nPosAt = rMailAddress.indexOf('@');
82  if (nPosAt<0 || rMailAddress.lastIndexOf('@')!=nPosAt)
83  return false;
84  const sal_Int32 nPosDot = rMailAddress.indexOf('.', nPosAt);
85  return !(nPosDot<0 || nPosDot-nPosAt<3 || rMailAddress.getLength()-nPosDot<3);
86 }
87 
88 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
89  SwMailMergeConfigItem const & rConfigItem,
90  uno::Reference< mail::XMailService >& rxInMailService,
91  const OUString& rInMailServerPassword,
92  const OUString& rOutMailServerPassword,
93  weld::Window* pDialogParentWindow )
94 {
95  uno::Reference< mail::XSmtpService > xSmtpServer;
96  uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
97  try
98  {
99  uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
100  mail::MailServiceProvider::create( xContext ) );
101  xSmtpServer.set(xMailServiceProvider->create(mail::MailServiceType_SMTP), uno::UNO_QUERY);
102 
103  uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
104 
105  if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
106  {
107  uno::Reference< mail::XMailService > xInMailService =
108  xMailServiceProvider->create(
109  rConfigItem.IsInServerPOP() ?
110  mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
111  //authenticate at the POP or IMAP server first
112  OUString sPasswd = rConfigItem.GetInServerPassword();
113  if(!rInMailServerPassword.isEmpty())
114  sPasswd = rInMailServerPassword;
115  uno::Reference<mail::XAuthenticator> xAuthenticator =
116  new SwAuthenticator(
117  rConfigItem.GetInServerUserName(),
118  sPasswd,
119  pDialogParentWindow);
120 
121  xInMailService->addConnectionListener(xConnectionListener);
122  //check connection
123  uno::Reference< uno::XCurrentContext> xConnectionContext =
125  rConfigItem.GetInServerName(),
126  rConfigItem.GetInServerPort(),
127  "Insecure");
128  xInMailService->connect(xConnectionContext, xAuthenticator);
129  rxInMailService = xInMailService;
130  }
131  uno::Reference< mail::XAuthenticator> xAuthenticator;
132  if(rConfigItem.IsAuthentication() &&
133  !rConfigItem.IsSMTPAfterPOP() &&
134  !rConfigItem.GetMailUserName().isEmpty())
135  {
136  OUString sPasswd = rConfigItem.GetMailPassword();
137  if(!rOutMailServerPassword.isEmpty())
138  sPasswd = rOutMailServerPassword;
139  xAuthenticator =
140  new SwAuthenticator(rConfigItem.GetMailUserName(),
141  sPasswd,
142  pDialogParentWindow);
143  }
144  else
145  xAuthenticator = new SwAuthenticator();
146  //just to check if the server exists
147  xSmtpServer->getSupportedConnectionTypes();
148  //check connection
149 
150  uno::Reference< uno::XCurrentContext> xConnectionContext =
152  rConfigItem.GetMailServer(),
153  rConfigItem.GetMailPort(),
154  rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
155  xSmtpServer->connect(xConnectionContext, xAuthenticator);
156  rxInMailService = xSmtpServer;
157  }
158  catch (const uno::Exception&)
159  {
160  TOOLS_WARN_EXCEPTION( "sw", "");
161  }
162  return xSmtpServer;
163 }
164 
165 } //namespace
166 
168 {
169  std::vector< OUString > aAddresses;
170  sal_uInt16 nRows;
171  sal_uInt16 nColumns;
172  sal_uInt16 nSelectedAddress;
174 
176  nRows(1),
177  nColumns(1),
178  nSelectedAddress(0),
179  bEnableScrollBar(false)
180  {
181  }
182 };
183 
185  const OUString& rAddress,
186  SwMailMergeConfigItem const & rConfigItem,
187  const Sequence< OUString>* pAssignments)
188 {
189  //find the column names in the address string (with name assignment!) and
190  //exchange the placeholder (like <Firstname>) with the database content
191  //unassigned columns are expanded to <not assigned>
192  Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
193  Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
194  Sequence< OUString> aAssignment = pAssignments ?
195  *pAssignments :
196  rConfigItem.GetColumnAssignment(
197  rConfigItem.GetCurrentDBData() );
198  const OUString* pAssignment = aAssignment.getConstArray();
199  const std::vector<std::pair<OUString, int>>& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
200  OUString sNotAssigned = "<" + SwResId(STR_NOTASSIGNED) + ">";
201 
202  bool bIncludeCountry = rConfigItem.IsIncludeCountry();
203  const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
204  bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
205  OUString sCountryColumn;
206  if( bSpecialReplacementForCountry )
207  {
208  sCountryColumn = rDefHeaders[MM_PART_COUNTRY].first;
209  Sequence< OUString> aSpecialAssignment =
210  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
211  if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
212  sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
213  }
214 
215  SwAddressIterator aIter(rAddress);
216  OUStringBuffer sAddress;
217  while(aIter.HasMore())
218  {
219  SwMergeAddressItem aItem = aIter.Next();
220  if(aItem.bIsColumn)
221  {
222  //get the default column name
223 
224  //find the appropriate assignment
225  OUString sConvertedColumn = aItem.sText;
226  auto nSize = std::min(sal_uInt32(rDefHeaders.size()), sal_uInt32(aAssignment.getLength()));
227  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
228  {
229  if (rDefHeaders[nColumn].first == aItem.sText &&
230  !pAssignment[nColumn].isEmpty())
231  {
232  sConvertedColumn = pAssignment[nColumn];
233  break;
234  }
235  }
236  if(!sConvertedColumn.isEmpty() &&
237  xColAccess.is() &&
238  xColAccess->hasByName(sConvertedColumn))
239  {
240  //get the content and exchange it in the address string
241  Any aCol = xColAccess->getByName(sConvertedColumn);
242  Reference< XColumn > xColumn;
243  aCol >>= xColumn;
244  if(xColumn.is())
245  {
246  try
247  {
248  OUString sReplace = xColumn->getString();
249 
250  if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
251  {
252  if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
253  aItem.sText = sReplace;
254  else
255  aItem.sText.clear();
256  }
257  else
258  {
259  aItem.sText = sReplace;
260  }
261  }
262  catch (const sdbc::SQLException&)
263  {
264  TOOLS_WARN_EXCEPTION( "sw", "");
265  }
266  }
267  }
268  else
269  {
270  aItem.sText = sNotAssigned;
271  }
272 
273  }
274  sAddress.append(aItem.sText);
275  }
276  return sAddress.makeStringAndClear();
277 }
278 
279 SwAddressPreview::SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xWindow)
280  : pImpl(new SwAddressPreview_Impl())
281  , m_xVScrollBar(std::move(xWindow))
282 {
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 = o3tl::narrowing<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  weld::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_scroll_thickness());
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 = o3tl::narrowing<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 != o3tl::narrowing<sal_uInt16>(nSelect))
440  {
441  pImpl->nSelectedAddress = o3tl::narrowing<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() > o3tl::make_unsigned(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 < o3tl::make_unsigned(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 != o3tl::narrowing<sal_uInt16>(nSelect))
484  {
485  pImpl->nSelectedAddress = o3tl::narrowing<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  {
661  Sequence<sal_Int8> aData;
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()
SwMergeAddressItem Next()
bool HasMore() const
exports com.sun.star. mail
virtual void SAL_CALL setBody(const css::uno::Reference< css::datatransfer::XTransferable > &_body) override
OUString const & GetMailServer() const
std::unique_ptr< weld::ScrolledWindow > m_xVScrollBar
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
SwAddressPreview(std::unique_ptr< weld::ScrolledWindow > xParent)
OUString m_aName
virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor &aFlavor) override
std::unique_ptr< ContentProperties > pData
SwConnectionContext(const OUString &rMailServer, sal_Int16 nPort, const OUString &rConnectionType)
signed char sal_Int8
bool IsSecureConnection() const
css::uno::Sequence< OUString > m_aCcRecipients
virtual sal_uInt64 TellEnd()
OUString & GetExcludeCountry() const
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
const StyleSettings & GetStyleSettings() const
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Reference< css::datatransfer::XTransferable > m_xBody
OString m_aMimeType
std::vector< OUString > aAddresses
sal_uInt64 Seek(sal_uInt64 nPos)
sal_uInt16 GetCode() const
const SwDBData & GetCurrentDBData() const
virtual short run() override
sal_Int16 GetMailPort() const
virtual css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override
weld::Window * m_pParentWindow
void DrawText_Impl(vcl::RenderContext &rRenderContext, const OUString &rAddress, const Point &rTopLeft, const Size &rSize, bool bIsSelected)
constexpr sal_uInt16 KEY_UP
Size const & GetOutputSizePixel() const
void SetAddress(const OUString &rAddress)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
constexpr tools::Long Width() const
virtual ~SwConnectionContext() override
virtual ~SwAuthenticator() override
void AddAddress(const OUString &rAddress)
The address string is a list of address elements separated by spaces and breaks.
OUString GetRealFilter() const
const vcl::Font & GetFont() const
Link< LinkParamNone *, void > m_aSelectHdl
css::uno::Sequence< OUString > m_aBccRecipients
std::mutex m_aMutex
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
void SetContext(Context _eNewContext)
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
constexpr OUStringLiteral aData
Definition: ww8scan.hxx:48
sal_Int16 GetInServerPort() const
css::uno::Reference< css::sdbc::XResultSet > const & GetResultSet() const
constexpr sal_uInt16 KEY_DOWN
exports com.sun.star. datatransfer
css::uno::Sequence< css::mail::MailAttachment > m_aAttachments
void SetLineColor()
css::uno::Sequence< OUString > m_aRecipients
const std::vector< std::pair< OUString, int > > & GetDefaultAddressHeaders() const
const Color & GetDisableColor() const
virtual void SAL_CALL disconnected(const css::lang::EventObject &aEvent) override
#define TOOLS_WARN_EXCEPTION(area, stream)
OUString CallSaveAsDialog(weld::Window *pParent, OUString &rFilter)
IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl, weld::ScrolledWindow &, void)
class SAL_NO_VTABLE XPropertySet
virtual OUString SAL_CALL getUserName() override
css::util::URL m_aURL
OUString m_sSenderAddress
void SetFillColor()
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
virtual void SAL_CALL addCcRecipient(const OUString &sRecipientAddress) override
unsigned char sal_Bool
virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor &aFlavor) override
css::uno::Type const & get()
void SelectAddress(sal_uInt16 nSelect)
const AllSettings & GetSettings() const
virtual css::uno::Sequence< OUString > SAL_CALL getRecipients() override
virtual ~SwMailMessage() override
bool IsInServerPOP() const
ErrCode GetErrorCode() const
virtual void SAL_CALL addRecipient(const OUString &sRecipientAddress) override
void SetColor(const Color &)
void SetMinLen(sal_uInt16 Len)
css::uno::Sequence< OUString > GetColumnAssignment(const SwDBData &rDBData) const
constexpr sal_uInt16 KEY_RIGHT
virtual css::uno::Sequence< OUString > SAL_CALL getBccRecipients() override
std::size_t ReadBytes(void *pData, std::size_t nSize)
OUString m_sSenderName
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
exports com.sun.star. beans
OUString const & GetInServerUserName() const
virtual css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getBody() override
SvStream * GetInStream()
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL connected(const css::lang::EventObject &aEvent) override
const vcl::KeyCode & GetKeyCode() const
weld::DrawingArea * GetDrawingArea() const
virtual OUString SAL_CALL getReplyToAddress() override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
OUString m_sReplyToAddress
#define ERRCODE_NONE
constexpr tools::Long Height() const
void SetFont(const vcl::Font &rNewFont)
virtual ~SwMailTransferable() override
void ReplaceSelectedAddress(const OUString &)
bool IsLeft() const
virtual void SAL_CALL addBccRecipient(const OUString &sRecipientAddress) override
RET_OK
virtual OUString SAL_CALL getSenderAddress() override
tools::Long AdjustWidth(tools::Long n)
virtual void SAL_CALL setReplyToAddress(const OUString &_replytoaddress) override
void SetPointFont(OutputDevice &rDevice, const vcl::Font &rFont)
SwMailTransferable(const OUString &rURL, const OUString &rName, const OUString &rMimeType)
virtual css::uno::Sequence< OUString > SAL_CALL getCcRecipients() override
OUString GetPassword() const
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
const Color & GetWindowColor() const
const Point & GetPosPixel() const
bool IsIncludeCountry() const
virtual css::uno::Any SAL_CALL getValueByName(const OUString &Name) override
Reference< XColumn > xColumn
virtual OUString SAL_CALL getSenderName() override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
sal_uInt16 GetSelectedAddress() const
bool IsSMTPAfterPOP() const
std::unique_ptr< SwAddressPreview_Impl > pImpl
virtual void SAL_CALL addAttachment(const css::mail::MailAttachment &aMailAttachment) override
bool CheckMailAddress(const OUString &rMailAddress)
constexpr sal_uInt16 KEY_LEFT
virtual ~SwConnectionListener() override
virtual void SAL_CALL setSubject(const OUString &_subject) override
constexpr OUStringLiteral first
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
OUString const & GetMailPassword() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
static OUString FillData(const OUString &rAddress, SwMailMergeConfigItem const &rConfigItem, const css::uno::Sequence< OUString > *pAssignments=nullptr)
const Color & GetWindowTextColor() const
void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
OUString const & GetMailUserName() const
sal_uInt16 nPos
virtual OUString SAL_CALL getPassword() override
sal_Int16 nValue
OUString const & GetInServerName() const
virtual css::uno::Sequence< css::mail::MailAttachment > SAL_CALL getAttachments() override