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