Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / dbui / mailmergehelper.cxx
blob4e6f7534da9ae216b226445a5aac7eb723e0d106
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
34 #include <comphelper/processfactory.hxx>
35 #include <o3tl/safeint.hxx>
36 #include <utility>
37 #include <vcl/event.hxx>
38 #include <vcl/settings.hxx>
39 #include <vcl/weldutils.hxx>
40 #include <comphelper/diagnose_ex.hxx>
41 #include <o3tl/string_view.hxx>
43 #include <sfx2/passwd.hxx>
45 #include <dbui.hrc>
46 #include <strings.hrc>
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::sdb;
52 using namespace ::com::sun::star::sdbc;
53 using namespace ::com::sun::star::sdbcx;
55 namespace SwMailMergeHelper
58 OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter)
60 ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
61 FileDialogFlags::NONE,
62 SwDocShell::Factory().GetFactoryName(), SfxFilterFlags::NONE, SfxFilterFlags::NONE, pParent);
63 aDialog.SetContext(sfx2::FileDialogHelper::WriterMailMergeSaveAs);
65 if (aDialog.Execute()!=ERRCODE_NONE)
67 return OUString();
70 rFilter = aDialog.GetRealFilter();
71 uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDialog.GetFilePicker();
72 return xFP->getSelectedFiles().getConstArray()[0];
76 simple address check: check for '@'
77 for at least one '.' after the '@',
78 for at least one character before the dot
79 and for at least two characters after the dot
81 bool CheckMailAddress( std::u16string_view aMailAddress )
83 const size_t nPosAt = aMailAddress.find('@');
84 if (nPosAt == std::u16string_view::npos || aMailAddress.rfind('@')!=nPosAt)
85 return false;
86 const size_t nPosDot = aMailAddress.find('.', nPosAt);
87 return !(nPosDot==std::u16string_view::npos || nPosDot-nPosAt<2 || aMailAddress.size()-nPosDot<3);
90 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
91 SwMailMergeConfigItem const & rConfigItem,
92 uno::Reference< mail::XMailService >& rxInMailService,
93 const OUString& rInMailServerPassword,
94 const OUString& rOutMailServerPassword,
95 weld::Window* pDialogParentWindow )
97 uno::Reference< mail::XSmtpService > xSmtpServer;
98 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
99 try
101 uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
102 mail::MailServiceProvider::create( xContext ) );
103 xSmtpServer.set(xMailServiceProvider->create(mail::MailServiceType_SMTP), uno::UNO_QUERY);
105 uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener);
107 if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
109 uno::Reference< mail::XMailService > xInMailService =
110 xMailServiceProvider->create(
111 rConfigItem.IsInServerPOP() ?
112 mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
113 //authenticate at the POP or IMAP server first
114 OUString sPasswd = rConfigItem.GetInServerPassword();
115 if(!rInMailServerPassword.isEmpty())
116 sPasswd = rInMailServerPassword;
117 uno::Reference<mail::XAuthenticator> xAuthenticator =
118 new SwAuthenticator(
119 rConfigItem.GetInServerUserName(),
120 sPasswd,
121 pDialogParentWindow);
123 xInMailService->addConnectionListener(xConnectionListener);
124 //check connection
125 uno::Reference< uno::XCurrentContext> xConnectionContext =
126 new SwConnectionContext(
127 rConfigItem.GetInServerName(),
128 rConfigItem.GetInServerPort(),
129 "Insecure");
130 xInMailService->connect(xConnectionContext, xAuthenticator);
131 rxInMailService = xInMailService;
133 uno::Reference< mail::XAuthenticator> xAuthenticator;
134 if(rConfigItem.IsAuthentication() &&
135 !rConfigItem.IsSMTPAfterPOP() &&
136 !rConfigItem.GetMailUserName().isEmpty())
138 OUString sPasswd = rConfigItem.GetMailPassword();
139 if(!rOutMailServerPassword.isEmpty())
140 sPasswd = rOutMailServerPassword;
141 xAuthenticator =
142 new SwAuthenticator(rConfigItem.GetMailUserName(),
143 sPasswd,
144 pDialogParentWindow);
146 else
147 xAuthenticator = new SwAuthenticator();
148 //just to check if the server exists
149 xSmtpServer->getSupportedConnectionTypes();
150 //check connection
152 uno::Reference< uno::XCurrentContext> xConnectionContext =
153 new SwConnectionContext(
154 rConfigItem.GetMailServer(),
155 rConfigItem.GetMailPort(),
156 rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
157 xSmtpServer->connect(xConnectionContext, xAuthenticator);
158 rxInMailService = xSmtpServer;
160 catch (const uno::Exception&)
162 TOOLS_WARN_EXCEPTION( "sw", "");
164 return xSmtpServer;
167 } //namespace
169 struct SwAddressPreview_Impl
171 std::vector< OUString > aAddresses;
172 sal_uInt16 nRows;
173 sal_uInt16 nColumns;
174 sal_uInt16 nSelectedAddress;
175 bool bEnableScrollBar;
177 SwAddressPreview_Impl() :
178 nRows(1),
179 nColumns(1),
180 nSelectedAddress(0),
181 bEnableScrollBar(false)
186 OUString SwAddressPreview::FillData(
187 const OUString& rAddress,
188 SwMailMergeConfigItem const & rConfigItem,
189 const Sequence< OUString>* pAssignments)
191 //find the column names in the address string (with name assignment!) and
192 //exchange the placeholder (like <Firstname>) with the database content
193 //unassigned columns are expanded to <not assigned>
194 Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
195 Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
196 Sequence< OUString> aAssignment = pAssignments ?
197 *pAssignments :
198 rConfigItem.GetColumnAssignment(
199 rConfigItem.GetCurrentDBData() );
200 const OUString* pAssignment = aAssignment.getConstArray();
201 const std::vector<std::pair<OUString, int>>& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
202 OUString sNotAssigned = "<" + SwResId(STR_NOTASSIGNED) + ">";
204 bool bIncludeCountry = rConfigItem.IsIncludeCountry();
205 const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
206 bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
207 OUString sCountryColumn;
208 if( bSpecialReplacementForCountry )
210 sCountryColumn = rDefHeaders[MM_PART_COUNTRY].first;
211 Sequence< OUString> aSpecialAssignment =
212 rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
213 if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
214 sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
217 SwAddressIterator aIter(rAddress);
218 OUStringBuffer sAddress;
219 while(aIter.HasMore())
221 SwMergeAddressItem aItem = aIter.Next();
222 if(aItem.bIsColumn)
224 //get the default column name
226 //find the appropriate assignment
227 OUString sConvertedColumn = aItem.sText;
228 auto nSize = std::min(sal_uInt32(rDefHeaders.size()), sal_uInt32(aAssignment.getLength()));
229 for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
231 if (rDefHeaders[nColumn].first == aItem.sText &&
232 !pAssignment[nColumn].isEmpty())
234 sConvertedColumn = pAssignment[nColumn];
235 break;
238 if(!sConvertedColumn.isEmpty() &&
239 xColAccess.is() &&
240 xColAccess->hasByName(sConvertedColumn))
242 //get the content and exchange it in the address string
243 Any aCol = xColAccess->getByName(sConvertedColumn);
244 Reference< XColumn > xColumn;
245 aCol >>= xColumn;
246 if(xColumn.is())
250 OUString sReplace = xColumn->getString();
252 if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
254 if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
255 aItem.sText = sReplace;
256 else
257 aItem.sText.clear();
259 else
261 aItem.sText = sReplace;
264 catch (const sdbc::SQLException&)
266 TOOLS_WARN_EXCEPTION( "sw", "");
270 else
272 aItem.sText = sNotAssigned;
276 sAddress.append(aItem.sText);
278 return sAddress.makeStringAndClear();
281 SwAddressPreview::SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xWindow)
282 : m_pImpl(new SwAddressPreview_Impl())
283 , m_xVScrollBar(std::move(xWindow))
285 m_xVScrollBar->connect_vadjustment_changed(LINK(this, SwAddressPreview, ScrollHdl));
288 SwAddressPreview::~SwAddressPreview()
292 IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl, weld::ScrolledWindow&, void)
294 Invalidate();
297 void SwAddressPreview::AddAddress(const OUString& rAddress)
299 m_pImpl->aAddresses.push_back(rAddress);
300 UpdateScrollBar();
303 void SwAddressPreview::SetAddress(const OUString& rAddress)
305 m_pImpl->aAddresses.clear();
306 m_pImpl->aAddresses.push_back(rAddress);
307 m_xVScrollBar->set_vpolicy(VclPolicyType::NEVER);
308 Invalidate();
311 sal_uInt16 SwAddressPreview::GetSelectedAddress()const
313 OSL_ENSURE(m_pImpl->nSelectedAddress < m_pImpl->aAddresses.size(), "selection invalid");
314 return m_pImpl->nSelectedAddress;
317 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
319 OSL_ENSURE(m_pImpl->nSelectedAddress < m_pImpl->aAddresses.size(), "selection invalid");
320 m_pImpl->nSelectedAddress = nSelect;
321 // now make it visible...
322 sal_uInt16 nSelectRow = nSelect / m_pImpl->nColumns;
323 sal_uInt16 nStartRow = m_xVScrollBar->vadjustment_get_value();
324 if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + m_pImpl->nRows) ))
325 m_xVScrollBar->vadjustment_set_value(nSelectRow);
328 void SwAddressPreview::Clear()
330 m_pImpl->aAddresses.clear();
331 m_pImpl->nSelectedAddress = 0;
332 UpdateScrollBar();
335 void SwAddressPreview::ReplaceSelectedAddress(const OUString& rNew)
337 m_pImpl->aAddresses[m_pImpl->nSelectedAddress] = rNew;
338 Invalidate();
341 void SwAddressPreview::RemoveSelectedAddress()
343 m_pImpl->aAddresses.erase(m_pImpl->aAddresses.begin() + m_pImpl->nSelectedAddress);
344 if(m_pImpl->nSelectedAddress)
345 --m_pImpl->nSelectedAddress;
346 UpdateScrollBar();
347 Invalidate();
350 void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
352 m_pImpl->nRows = nRows;
353 m_pImpl->nColumns = nColumns;
354 UpdateScrollBar();
357 void SwAddressPreview::EnableScrollBar()
359 m_pImpl->bEnableScrollBar = true;
362 void SwAddressPreview::UpdateScrollBar()
364 if (m_pImpl->nColumns)
366 sal_uInt16 nResultingRows = o3tl::narrowing<sal_uInt16>(m_pImpl->aAddresses.size() + m_pImpl->nColumns - 1) / m_pImpl->nColumns;
367 ++nResultingRows;
368 auto nValue = m_xVScrollBar->vadjustment_get_value();
369 if (nValue > nResultingRows)
370 nValue = nResultingRows;
371 m_xVScrollBar->set_vpolicy(m_pImpl->bEnableScrollBar && nResultingRows > m_pImpl->nRows ? VclPolicyType::ALWAYS : VclPolicyType::NEVER);
372 m_xVScrollBar->vadjustment_configure(nValue, 0, nResultingRows, 1, 10, m_pImpl->nRows);
376 void SwAddressPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
378 const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
379 rRenderContext.SetFillColor(rSettings.GetWindowColor());
380 rRenderContext.SetLineColor(COL_TRANSPARENT);
381 rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), GetOutputSizePixel()));
382 Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
383 rRenderContext.SetLineColor(aPaintColor);
385 weld::SetPointFont(rRenderContext, GetDrawingArea()->get_font());
386 vcl::Font aFont(rRenderContext.GetFont());
387 aFont.SetColor(aPaintColor);
388 rRenderContext.SetFont(aFont);
390 Size aSize(GetOutputSizePixel());
391 sal_uInt16 nStartRow = 0;
392 if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER)
394 aSize.AdjustWidth(-m_xVScrollBar->get_scroll_thickness());
395 nStartRow = m_xVScrollBar->vadjustment_get_value();
397 Size aPartSize(aSize.Width() / m_pImpl->nColumns,
398 aSize.Height() / m_pImpl->nRows);
399 aPartSize.AdjustWidth( -2 );
400 aPartSize.AdjustHeight( -2 );
402 sal_uInt16 nAddress = nStartRow * m_pImpl->nColumns;
403 const sal_uInt16 nNumAddresses = o3tl::narrowing<sal_uInt16>(m_pImpl->aAddresses.size());
404 for (sal_uInt16 nRow = 0; nRow < m_pImpl->nRows ; ++nRow)
406 for (sal_uInt16 nCol = 0; nCol < m_pImpl->nColumns; ++nCol)
408 if (nAddress >= nNumAddresses)
409 break;
410 Point aPos(nCol * aPartSize.Width(),
411 nRow * aPartSize.Height());
412 aPos.Move(1, 1);
413 bool bIsSelected = nAddress == m_pImpl->nSelectedAddress;
414 if ((m_pImpl->nColumns * m_pImpl->nRows) == 1)
415 bIsSelected = false;
416 OUString adr(m_pImpl->aAddresses[nAddress]);
417 DrawText_Impl(rRenderContext, adr, aPos, aPartSize, bIsSelected);
418 ++nAddress;
421 rRenderContext.SetClipRegion();
424 bool SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
426 if (rMEvt.IsLeft() && m_pImpl->nRows && m_pImpl->nColumns)
428 //determine the selected address
429 const Point& rMousePos = rMEvt.GetPosPixel();
430 Size aSize(GetOutputSizePixel());
431 Size aPartSize( aSize.Width()/m_pImpl->nColumns, aSize.Height()/m_pImpl->nRows );
432 sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
433 if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER)
435 nRow += m_xVScrollBar->vadjustment_get_value();
437 sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
438 sal_uInt32 nSelect = nRow * m_pImpl->nColumns + nCol;
440 if( nSelect < m_pImpl->aAddresses.size() &&
441 m_pImpl->nSelectedAddress != o3tl::narrowing<sal_uInt16>(nSelect))
443 m_pImpl->nSelectedAddress = o3tl::narrowing<sal_uInt16>(nSelect);
444 m_aSelectHdl.Call(nullptr);
446 Invalidate();
448 return true;
451 bool SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
453 sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
454 bool bHandled = false;
455 if (m_pImpl->nRows && m_pImpl->nColumns)
457 sal_uInt32 nSelectedRow = m_pImpl->nSelectedAddress / m_pImpl->nColumns;
458 sal_uInt32 nSelectedColumn = m_pImpl->nSelectedAddress - (nSelectedRow * m_pImpl->nColumns);
459 switch(nKey)
461 case KEY_UP:
462 if(nSelectedRow)
463 --nSelectedRow;
464 bHandled = true;
465 break;
466 case KEY_DOWN:
467 if(m_pImpl->aAddresses.size() > o3tl::make_unsigned(m_pImpl->nSelectedAddress + m_pImpl->nColumns))
468 ++nSelectedRow;
469 bHandled = true;
470 break;
471 case KEY_LEFT:
472 if(nSelectedColumn)
473 --nSelectedColumn;
474 bHandled = true;
475 break;
476 case KEY_RIGHT:
477 if(nSelectedColumn < o3tl::make_unsigned(m_pImpl->nColumns - 1) &&
478 m_pImpl->aAddresses.size() - 1 > m_pImpl->nSelectedAddress )
479 ++nSelectedColumn;
480 bHandled = true;
481 break;
483 sal_uInt32 nSelect = nSelectedRow * m_pImpl->nColumns + nSelectedColumn;
484 if( nSelect < m_pImpl->aAddresses.size() &&
485 m_pImpl->nSelectedAddress != o3tl::narrowing<sal_uInt16>(nSelect))
487 m_pImpl->nSelectedAddress = o3tl::narrowing<sal_uInt16>(nSelect);
488 m_aSelectHdl.Call(nullptr);
489 Invalidate();
492 return bHandled;
495 void SwAddressPreview::DrawText_Impl(vcl::RenderContext& rRenderContext, std::u16string_view rAddress,
496 const Point& rTopLeft, const Size& rSize, bool bIsSelected)
498 rRenderContext.SetClipRegion(vcl::Region(tools::Rectangle(rTopLeft, rSize)));
499 if (bIsSelected)
501 //selection rectangle
502 rRenderContext.SetFillColor(COL_TRANSPARENT);
503 rRenderContext.DrawRect(tools::Rectangle(rTopLeft, rSize));
505 sal_Int32 nHeight = GetTextHeight();
506 Point aStart = rTopLeft;
507 //put it away from the border
508 aStart.Move(2, 2);
509 sal_Int32 nPos = 0;
512 rRenderContext.DrawText(aStart, OUString(o3tl::getToken(rAddress, 0, '\n', nPos)));
513 aStart.AdjustY(nHeight );
515 while (nPos >= 0);
518 SwMergeAddressItem SwAddressIterator::Next()
520 //currently the string may either start with a '<' then it's a column
521 //otherwise it's simple text maybe containing a return
522 SwMergeAddressItem aRet;
523 if(!m_sAddress.isEmpty())
525 if(m_sAddress[0] == '<')
527 aRet.bIsColumn = true;
528 sal_Int32 nClose = m_sAddress.indexOf('>');
529 OSL_ENSURE(nClose != -1, "closing '>' not found");
530 if( nClose != -1 )
532 aRet.sText = m_sAddress.copy(1, nClose - 1);
533 m_sAddress = m_sAddress.copy(nClose + 1);
535 else
537 aRet.sText = m_sAddress.copy(1, 1);
538 m_sAddress = m_sAddress.copy(1);
541 else
543 sal_Int32 nOpen = m_sAddress.indexOf('<');
544 sal_Int32 nReturn = m_sAddress.indexOf('\n');
545 if(nReturn == 0)
547 aRet.bIsReturn = true;
548 aRet.sText = "\n";
549 m_sAddress = m_sAddress.copy(1);
551 else if(-1 == nOpen && -1 == nReturn)
553 aRet.sText = m_sAddress;
554 m_sAddress.clear();
556 else
558 if (nOpen == -1)
559 nOpen = m_sAddress.getLength();
560 if (nReturn == -1)
561 nReturn = m_sAddress.getLength();
562 sal_Int32 nTarget = std::min(nOpen, nReturn);
563 aRet.sText = m_sAddress.copy(0, nTarget);
564 m_sAddress = m_sAddress.copy(nTarget);
568 return aRet;
572 SwAuthenticator::~SwAuthenticator()
576 OUString SwAuthenticator::getUserName( )
578 return m_aUserName;
581 OUString SwAuthenticator::getPassword( )
583 if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow)
585 SfxPasswordDialog aPasswdDlg(m_pParentWindow);
586 aPasswdDlg.SetMinLen(0);
587 if (RET_OK == aPasswdDlg.run())
588 m_aPassword = aPasswdDlg.GetPassword();
590 return m_aPassword;
593 SwConnectionContext::SwConnectionContext(
594 OUString aMailServer, sal_Int16 nPort,
595 OUString aConnectionType) :
596 m_sMailServer(std::move(aMailServer)),
597 m_nPort(nPort),
598 m_sConnectionType(std::move(aConnectionType))
602 SwConnectionContext::~SwConnectionContext()
606 uno::Any SwConnectionContext::getValueByName( const OUString& rName )
608 uno::Any aRet;
609 if( rName == "ServerName" )
610 aRet <<= m_sMailServer;
611 else if( rName == "Port" )
612 aRet <<= static_cast<sal_Int32>(m_nPort);
613 else if( rName == "ConnectionType" )
614 aRet <<= m_sConnectionType;
615 return aRet;
618 SwConnectionListener::~SwConnectionListener()
622 void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
626 void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
630 void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
634 SwMailTransferable::SwMailTransferable(OUString aBody, OUString aMimeType) :
635 m_aMimeType(std::move( aMimeType )),
636 m_sBody(std::move( aBody )),
637 m_bIsBody( true )
641 SwMailTransferable::SwMailTransferable(OUString aURL,
642 OUString aName, OUString aMimeType) :
643 m_aMimeType(std::move( aMimeType )),
644 m_aURL(std::move(aURL)),
645 m_aName(std::move( aName )),
646 m_bIsBody( false )
650 SwMailTransferable::~SwMailTransferable()
654 uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
656 uno::Any aRet;
657 if( m_bIsBody )
658 aRet <<= m_sBody;
659 else
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)
666 aData.realloc(pStream->TellEnd());
667 pStream->Seek(0);
668 sal_Int8 * pData = aData.getArray();
669 pStream->ReadBytes( pData, aData.getLength() );
671 aRet <<= aData;
673 return aRet;
676 uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
678 datatransfer::DataFlavor aRet;
679 aRet.MimeType = m_aMimeType;
680 if( m_bIsBody )
682 aRet.DataType = cppu::UnoType<OUString>::get();
684 else
686 aRet.HumanPresentableName = m_aName;
687 aRet.DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get();
689 return { aRet };
692 sal_Bool SwMailTransferable::isDataFlavorSupported(
693 const datatransfer::DataFlavor& aFlavor )
695 return (aFlavor.MimeType == m_aMimeType);
698 uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( )
700 return uno::Reference< beans::XPropertySetInfo >();
703 void SwMailTransferable::setPropertyValue( const OUString& , const uno::Any& )
707 uno::Any SwMailTransferable::getPropertyValue( const OUString& rPropertyName )
709 uno::Any aRet;
710 if ( rPropertyName == "URL" )
711 aRet <<= m_aURL;
712 return aRet;
715 void SwMailTransferable::addPropertyChangeListener(
716 const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
720 void SwMailTransferable::removePropertyChangeListener(
721 const OUString&,
722 const uno::Reference< beans::XPropertyChangeListener >& )
726 void SwMailTransferable::addVetoableChangeListener(
727 const OUString&,
728 const uno::Reference< beans::XVetoableChangeListener >& )
732 void SwMailTransferable::removeVetoableChangeListener(
733 const OUString& ,
734 const uno::Reference< beans::XVetoableChangeListener >& )
738 SwMailMessage::SwMailMessage()
742 SwMailMessage::~SwMailMessage()
746 OUString SwMailMessage::getSenderName()
748 return m_sSenderName;
751 OUString SwMailMessage::getSenderAddress()
753 return m_sSenderAddress;
756 OUString SwMailMessage::getReplyToAddress()
758 return m_sReplyToAddress;
761 void SwMailMessage::setReplyToAddress( const OUString& _replytoaddress )
763 m_sReplyToAddress = _replytoaddress;
766 OUString SwMailMessage::getSubject()
768 return m_sSubject;
771 void SwMailMessage::setSubject( const OUString& _subject )
773 m_sSubject = _subject;
776 uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody()
778 return m_xBody;
781 void SwMailMessage::setBody(
782 const uno::Reference< datatransfer::XTransferable >& rBody )
784 m_xBody = rBody;
787 void SwMailMessage::addRecipient( const OUString& rRecipientAddress )
789 m_aRecipients.realloc(m_aRecipients.getLength() + 1);
790 m_aRecipients.getArray()[m_aRecipients.getLength() - 1] = rRecipientAddress;
793 void SwMailMessage::addCcRecipient( const OUString& rRecipientAddress )
795 m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
796 m_aCcRecipients.getArray()[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
800 void SwMailMessage::addBccRecipient( const OUString& rRecipientAddress )
802 m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
803 m_aBccRecipients.getArray()[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
806 uno::Sequence< OUString > SwMailMessage::getRecipients( )
808 return m_aRecipients;
811 uno::Sequence< OUString > SwMailMessage::getCcRecipients( )
813 return m_aCcRecipients;
816 uno::Sequence< OUString > SwMailMessage::getBccRecipients( )
818 return m_aBccRecipients;
821 void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
823 m_aAttachments.realloc(m_aAttachments.getLength() + 1);
824 m_aAttachments.getArray()[m_aAttachments.getLength() - 1] = rMailAttachment;
827 uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
829 return m_aAttachments;
832 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */