update credits
[LibreOffice.git] / sw / source / ui / dbui / mailmergehelper.cxx
blobb5d75e07d961711b4e11c0225a69037e551051fd
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 <svtools/stdctrl.hxx>
23 #include <mmconfigitem.hxx>
24 #include <docsh.hxx>
25 #include <sfx2/filedlghelper.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <sfx2/app.hxx>
28 #include <sfx2/fcontnr.hxx>
29 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
30 #include <com/sun/star/sdb/XColumn.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
33 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
34 #include "com/sun/star/mail/MailServiceProvider.hpp"
35 #include "com/sun/star/mail/XSmtpService.hpp"
36 #include <comphelper/processfactory.hxx>
37 #include <comphelper/string.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <sfx2/passwd.hxx>
41 #include <dbui.hrc>
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::sdb;
47 using namespace ::com::sun::star::sdbc;
48 using namespace ::com::sun::star::sdbcx;
51 namespace SwMailMergeHelper
54 String CallSaveAsDialog(String& rFilter)
56 ErrCode nRet;
57 String sFactory(OUString::createFromAscii(SwDocShell::Factory().GetShortName()));
58 ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
60 sFactory );
62 String sRet;
63 nRet = aDialog.Execute();
64 if(ERRCODE_NONE == nRet)
66 uno::Reference < ui::dialogs::XFilePicker > xFP = aDialog.GetFilePicker();
67 sRet = xFP->getFiles().getConstArray()[0];
68 rFilter = aDialog.GetRealFilter();
70 return sRet;
74 simple address check: check for '@'
75 for at least one '.' after the '@'
76 and for at least to characters before and after the dot
78 bool CheckMailAddress( const OUString& rMailAddress )
80 String sAddress(rMailAddress);
81 if (!(comphelper::string::getTokenCount(sAddress, '@') == 2))
82 return false;
83 sAddress = sAddress.GetToken(1, '@');
84 if (comphelper::string::getTokenCount(sAddress, '.') < 2)
85 return false;
86 if(sAddress.GetToken( 0, '.').Len() < 2 || sAddress.GetToken( 1, '.').Len() < 2)
87 return false;
88 return true;
91 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
92 SwMailMergeConfigItem& rConfigItem,
93 uno::Reference< mail::XMailService >& rxInMailService,
94 const String& rInMailServerPassword,
95 const String& rOutMailServerPassword,
96 Window* pDialogParentWindow )
98 uno::Reference< mail::XSmtpService > xSmtpServer;
99 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
102 uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
103 mail::MailServiceProvider::create( xContext ) );
104 xSmtpServer = uno::Reference< mail::XSmtpService > (
105 xMailServiceProvider->create(
106 mail::MailServiceType_SMTP
107 ), uno::UNO_QUERY);
109 uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
111 if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
113 uno::Reference< mail::XMailService > xInMailService =
114 xMailServiceProvider->create(
115 rConfigItem.IsInServerPOP() ?
116 mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
117 //authenticate at the POP or IMAP server first
118 String sPasswd = rConfigItem.GetInServerPassword();
119 if(rInMailServerPassword.Len())
120 sPasswd = rInMailServerPassword;
121 uno::Reference<mail::XAuthenticator> xAuthenticator =
122 new SwAuthenticator(
123 rConfigItem.GetInServerUserName(),
124 sPasswd,
125 pDialogParentWindow);
127 xInMailService->addConnectionListener(xConnectionListener);
128 //check connection
129 uno::Reference< uno::XCurrentContext> xConnectionContext =
130 new SwConnectionContext(
131 rConfigItem.GetInServerName(),
132 rConfigItem.GetInServerPort(),
133 OUString("Insecure"));
134 xInMailService->connect(xConnectionContext, xAuthenticator);
135 rxInMailService = xInMailService;
137 uno::Reference< mail::XAuthenticator> xAuthenticator;
138 if(rConfigItem.IsAuthentication() &&
139 !rConfigItem.IsSMTPAfterPOP() &&
140 !rConfigItem.GetMailUserName().isEmpty())
142 String sPasswd = rConfigItem.GetMailPassword();
143 if(rOutMailServerPassword.Len())
144 sPasswd = rOutMailServerPassword;
145 xAuthenticator =
146 new SwAuthenticator(rConfigItem.GetMailUserName(),
147 sPasswd,
148 pDialogParentWindow);
150 else
151 xAuthenticator = new SwAuthenticator();
152 //just to check if the server exists
153 xSmtpServer->getSupportedConnectionTypes();
154 //check connection
156 uno::Reference< uno::XCurrentContext> xConnectionContext =
157 new SwConnectionContext(
158 rConfigItem.GetMailServer(),
159 rConfigItem.GetMailPort(),
160 rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
161 xSmtpServer->connect(xConnectionContext, xAuthenticator);
162 rxInMailService = uno::Reference< mail::XMailService >( xSmtpServer, uno::UNO_QUERY );
164 catch (const uno::Exception&)
166 OSL_FAIL("exception caught");
168 return xSmtpServer;
172 } //namespace
174 SwBoldFixedInfo::SwBoldFixedInfo(Window* pParent, const ResId& rResId) :
175 FixedInfo(pParent, rResId)
177 Font aFont = GetFont();
178 aFont.SetWeight( WEIGHT_BOLD );
179 SetFont( aFont );
182 SwBoldFixedInfo::~SwBoldFixedInfo()
186 struct SwAddressPreview_Impl
188 ::std::vector< OUString > aAdresses;
189 sal_uInt16 nRows;
190 sal_uInt16 nColumns;
191 sal_uInt16 nSelectedAddress;
192 bool bEnableScrollBar;
194 SwAddressPreview_Impl() :
195 nRows(1),
196 nColumns(1),
197 nSelectedAddress(0),
198 bEnableScrollBar(false)
203 SwAddressPreview::SwAddressPreview(Window* pParent, const ResId rResId) :
204 Window( pParent, rResId ),
205 aVScrollBar(this, WB_VSCROLL),
206 pImpl(new SwAddressPreview_Impl())
208 aVScrollBar.SetScrollHdl(LINK(this, SwAddressPreview, ScrollHdl));
209 Size aSize(GetOutputSizePixel());
210 Size aScrollSize(aVScrollBar.GetSizePixel());
211 aScrollSize.Height() = aSize.Height();
212 aVScrollBar.SetSizePixel(aScrollSize);
213 Point aSrollPos(aSize.Width() - aScrollSize.Width(), 0);
214 aVScrollBar.SetPosPixel(aSrollPos);
215 Show();
218 SwAddressPreview::~SwAddressPreview()
222 IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl)
224 Invalidate();
225 return 0;
228 void SwAddressPreview::AddAddress(const OUString& rAddress)
230 pImpl->aAdresses.push_back(rAddress);
231 UpdateScrollBar();
234 void SwAddressPreview::SetAddress(const OUString& rAddress)
236 pImpl->aAdresses.clear();
237 pImpl->aAdresses.push_back(rAddress);
238 aVScrollBar.Show(sal_False);
239 Invalidate();
242 sal_uInt16 SwAddressPreview::GetSelectedAddress()const
244 OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
245 return pImpl->nSelectedAddress;
248 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
250 OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
251 pImpl->nSelectedAddress = nSelect;
252 // now make it visible..
253 sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
254 sal_uInt16 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
255 if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
256 aVScrollBar.SetThumbPos( nSelectRow );
259 void SwAddressPreview::Clear()
261 pImpl->aAdresses.clear();
262 pImpl->nSelectedAddress = 0;
263 UpdateScrollBar();
266 void SwAddressPreview::ReplaceSelectedAddress(const OUString& rNew)
268 pImpl->aAdresses[pImpl->nSelectedAddress] = rNew;
269 Invalidate();
272 void SwAddressPreview::RemoveSelectedAddress()
274 pImpl->aAdresses.erase(pImpl->aAdresses.begin() + pImpl->nSelectedAddress);
275 if(pImpl->nSelectedAddress)
276 --pImpl->nSelectedAddress;
277 UpdateScrollBar();
278 Invalidate();
281 void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
283 pImpl->nRows = nRows;
284 pImpl->nColumns = nColumns;
285 UpdateScrollBar();
288 void SwAddressPreview::EnableScrollBar(bool bEnable)
290 pImpl->bEnableScrollBar = bEnable;
293 void SwAddressPreview::UpdateScrollBar()
295 if(pImpl->nColumns)
297 aVScrollBar.SetVisibleSize(pImpl->nRows);
298 sal_uInt16 nResultingRows = (sal_uInt16)(pImpl->aAdresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
299 ++nResultingRows;
300 aVScrollBar.Show(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows);
301 aVScrollBar.SetRange(Range(0, nResultingRows));
302 if(aVScrollBar.GetThumbPos() > nResultingRows)
303 aVScrollBar.SetThumbPos(nResultingRows);
307 void SwAddressPreview::Paint(const Rectangle&)
309 const StyleSettings& rSettings = GetSettings().GetStyleSettings();
310 SetFillColor(rSettings.GetWindowColor());
311 SetLineColor( Color(COL_TRANSPARENT) );
312 DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) );
313 Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
314 SetLineColor(aPaintColor);
315 Font aFont(GetFont());
316 aFont.SetColor(aPaintColor);
317 SetFont(aFont);
319 Size aSize = GetOutputSizePixel();
320 sal_uInt16 nStartRow = 0;
321 if(aVScrollBar.IsVisible())
323 aSize.Width() -= aVScrollBar.GetSizePixel().Width();
324 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
326 Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
327 aPartSize.Width() -= 2;
328 aPartSize.Height() -= 2;
330 sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
331 const sal_uInt16 nNumAddresses = static_cast< sal_uInt16 >(pImpl->aAdresses.size());
332 for(sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
334 for(sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
336 if(nAddress >= nNumAddresses)
337 break;
338 Point aPos(nCol * aPartSize.Width(), (nRow) * aPartSize.Height());
339 aPos.Move(1,1);
340 bool bIsSelected = nAddress == pImpl->nSelectedAddress;
341 if((pImpl->nColumns * pImpl->nRows) == 1)
342 bIsSelected = false;
343 OUString adr(pImpl->aAdresses[nAddress]);
344 DrawText_Impl(adr,aPos,aPartSize,bIsSelected);
345 ++nAddress;
348 SetClipRegion();
351 void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
353 Window::MouseButtonDown(rMEvt);
354 if(rMEvt.IsLeft() && ( pImpl->nRows || pImpl->nColumns))
356 //determine the selected address
357 const Point& rMousePos = rMEvt.GetPosPixel();
358 Size aSize(GetOutputSizePixel());
359 Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
360 sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
361 if(aVScrollBar.IsVisible())
363 nRow += (sal_uInt16)aVScrollBar.GetThumbPos();
365 sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
366 sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
368 if( nSelect < pImpl->aAdresses.size() &&
369 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
371 pImpl->nSelectedAddress = (sal_uInt16)nSelect;
372 m_aSelectHdl.Call(this);
374 Invalidate();
378 void SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
380 sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
381 if(pImpl->nRows || pImpl->nColumns)
383 sal_uInt32 nSelectedRow = (pImpl->nSelectedAddress + 1)/ pImpl->nColumns;
384 sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress % nSelectedRow;
385 switch(nKey)
387 case KEY_UP:
388 if(nSelectedRow)
389 --nSelectedRow;
390 break;
391 case KEY_DOWN:
392 if(pImpl->aAdresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
393 ++nSelectedRow;
394 break;
395 case KEY_LEFT:
396 if(nSelectedColumn)
397 --nSelectedColumn;
398 break;
399 case KEY_RIGHT:
400 if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
401 pImpl->aAdresses.size() - 1 > pImpl->nSelectedAddress )
402 ++nSelectedColumn;
403 break;
405 sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
406 if( nSelect < pImpl->aAdresses.size() &&
407 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
409 pImpl->nSelectedAddress = (sal_uInt16)nSelect;
410 m_aSelectHdl.Call(this);
411 Invalidate();
414 else
415 Window::KeyInput(rKEvt);
418 void SwAddressPreview::StateChanged( StateChangedType nStateChange )
420 if(nStateChange == STATE_CHANGE_ENABLE)
421 Invalidate();
422 Window::StateChanged(nStateChange);
425 void SwAddressPreview::DrawText_Impl(
426 const OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected)
428 SetClipRegion( Region( Rectangle(rTopLeft, rSize)) );
429 if(bIsSelected)
431 //selection rectangle
432 SetFillColor(Color(COL_TRANSPARENT));
433 DrawRect(Rectangle(rTopLeft, rSize));
435 sal_Int32 nHeight = GetTextHeight();
436 String sAddress(rAddress);
437 sal_uInt16 nTokens = comphelper::string::getTokenCount(sAddress, '\n');
438 Point aStart = rTopLeft;
439 //put it away from the border
440 aStart.Move( 2, 2);
441 for(sal_uInt16 nToken = 0; nToken < nTokens; nToken++)
443 DrawText( aStart, sAddress.GetToken(nToken, '\n') );
444 aStart.Y() += nHeight;
448 String SwAddressPreview::FillData(
449 const OUString& rAddress,
450 SwMailMergeConfigItem& rConfigItem,
451 const Sequence< OUString>* pAssignments)
453 //find the column names in the address string (with name assignment!) and
454 //exchange the placeholder (like <Firstname>) with the database content
455 //unassigned columns are expanded to <not assigned>
456 Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
457 Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
458 Sequence< OUString> aAssignment = pAssignments ?
459 *pAssignments :
460 rConfigItem.GetColumnAssignment(
461 rConfigItem.GetCurrentDBData() );
462 const OUString* pAssignment = aAssignment.getConstArray();
463 const ResStringArray& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
464 String sAddress(rAddress);
465 String sNotAssigned(SW_RES(STR_NOTASSIGNED));
466 sNotAssigned.Insert('<', 0);
467 sNotAssigned += '>';
469 sal_Bool bIncludeCountry = rConfigItem.IsIncludeCountry();
470 const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
471 bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
472 String sCountryColumn;
473 if( bSpecialReplacementForCountry )
475 sCountryColumn = rDefHeaders.GetString(MM_PART_COUNTRY);
476 Sequence< OUString> aSpecialAssignment =
477 rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
478 if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
479 sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
482 SwAddressIterator aIter(sAddress);
483 sAddress.Erase();
484 while(aIter.HasMore())
486 SwMergeAddressItem aItem = aIter.Next();
487 if(aItem.bIsColumn)
489 //get the default column name
491 //find the appropriate assignment
492 String sConvertedColumn = aItem.sText;
493 for(sal_uInt16 nColumn = 0;
494 nColumn < rDefHeaders.Count() && nColumn < aAssignment.getLength();
495 ++nColumn)
497 if (rDefHeaders.GetString(nColumn).equals(aItem.sText) &&
498 !pAssignment[nColumn].isEmpty())
500 sConvertedColumn = pAssignment[nColumn];
501 break;
504 if(sConvertedColumn.Len() &&
505 xColAccess.is() &&
506 xColAccess->hasByName(sConvertedColumn))
508 //get the content and exchange it in the address string
509 Any aCol = xColAccess->getByName(sConvertedColumn);
510 Reference< XColumn > xColumn;
511 aCol >>= xColumn;
512 if(xColumn.is())
516 OUString sReplace = xColumn->getString();
518 if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
520 if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
521 aItem.sText = sReplace;
522 else
523 aItem.sText.Erase();
525 else
527 aItem.sText = sReplace;
530 catch (const sdbc::SQLException&)
532 OSL_FAIL("SQLException caught");
536 else
538 aItem.sText = sNotAssigned;
542 sAddress += aItem.sText;
544 return sAddress;
547 SwMergeAddressItem SwAddressIterator::Next()
549 //currently the string may either start with a '<' then it's a column
550 //otherwise it's simple text maybe containing a return
551 SwMergeAddressItem aRet;
552 if(sAddress.Len())
554 if(sAddress.GetChar(0) == '<')
556 aRet.bIsColumn = true;
557 xub_StrLen nClose = sAddress.Search('>');
558 OSL_ENSURE(nClose != STRING_NOTFOUND, "closing '>' not found");
559 if( nClose != STRING_NOTFOUND )
561 aRet.sText = sAddress.Copy(1, nClose - 1);
562 sAddress.Erase(0, nClose + 1);
564 else
566 aRet.sText = sAddress.Copy(1, 1);
567 sAddress.Erase(0, 1);
570 else
572 xub_StrLen nOpen = sAddress.Search('<');
573 xub_StrLen nReturn = sAddress.Search('\n');
574 if(nReturn == 0)
576 aRet.bIsReturn = true;
577 aRet.sText = '\n';
578 sAddress.Erase(0, 1);
580 else if(STRING_NOTFOUND == nOpen && STRING_NOTFOUND == nReturn)
582 nOpen = sAddress.Len();
583 aRet.sText = sAddress;
584 sAddress.Erase();
586 else
588 xub_StrLen nTarget = ::std::min(nOpen, nReturn);
589 aRet.sText = sAddress.Copy(0, nTarget);
590 sAddress.Erase(0, nTarget);
594 return aRet;
598 SwAuthenticator::~SwAuthenticator()
602 OUString SwAuthenticator::getUserName( ) throw (RuntimeException)
604 return m_aUserName;
607 OUString SwAuthenticator::getPassword( ) throw (RuntimeException)
609 if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow)
611 SfxPasswordDialog* pPasswdDlg =
612 new SfxPasswordDialog( m_pParentWindow );
613 pPasswdDlg->SetMinLen( 0 );
614 if(RET_OK == pPasswdDlg->Execute())
615 m_aPassword = pPasswdDlg->GetPassword();
617 return m_aPassword;
620 SwConnectionContext::SwConnectionContext(
621 const OUString& rMailServer, sal_Int16 nPort,
622 const OUString& rConnectionType) :
623 m_sMailServer(rMailServer),
624 m_nPort(nPort),
625 m_sConnectionType(rConnectionType)
629 SwConnectionContext::~SwConnectionContext()
633 uno::Any SwConnectionContext::getValueByName( const OUString& rName )
634 throw (uno::RuntimeException)
636 uno::Any aRet;
637 if( !rName.compareToAscii( "ServerName" ))
638 aRet <<= m_sMailServer;
639 else if( !rName.compareToAscii( "Port" ))
640 aRet <<= (sal_Int32) m_nPort;
641 else if( !rName.compareToAscii( "ConnectionType" ))
642 aRet <<= m_sConnectionType;
643 return aRet;
646 SwConnectionListener::~SwConnectionListener()
650 void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
651 throw (uno::RuntimeException)
655 void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
656 throw (uno::RuntimeException)
660 void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
661 throw(uno::RuntimeException)
665 SwMailTransferable::SwMailTransferable(const OUString& rBody, const OUString& rMimeType) :
666 cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
667 m_aMimeType( rMimeType ),
668 m_sBody( rBody ),
669 m_bIsBody( true )
673 SwMailTransferable::SwMailTransferable(const OUString& rURL,
674 const OUString& rName, const OUString& rMimeType) :
675 cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
676 m_aMimeType( rMimeType ),
677 m_aURL(rURL),
678 m_aName( rName ),
679 m_bIsBody( false )
683 SwMailTransferable::~SwMailTransferable()
687 uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
688 throw (datatransfer::UnsupportedFlavorException,
689 io::IOException, uno::RuntimeException)
691 uno::Any aRet;
692 if( m_bIsBody )
693 aRet <<= OUString(m_sBody);
694 else
696 Sequence<sal_Int8> aData;
697 SfxMedium aMedium( m_aURL, STREAM_STD_READ );
698 SvStream* pStream = aMedium.GetInStream();
699 if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
701 pStream->Seek(STREAM_SEEK_TO_END);
702 aData.realloc(pStream->Tell());
703 pStream->Seek(0);
704 sal_Int8 * pData = aData.getArray();
705 pStream->Read( pData, aData.getLength() );
707 aRet <<= aData;
709 return aRet;
712 uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
713 throw (uno::RuntimeException)
715 uno::Sequence< datatransfer::DataFlavor > aRet(1);
716 aRet[0].MimeType = m_aMimeType;
717 if( m_bIsBody )
719 aRet[0].DataType = getCppuType((OUString*)0);
721 else
723 aRet[0].HumanPresentableName = m_aName;
724 aRet[0].DataType = getCppuType((uno::Sequence<sal_Int8>*)0);
726 return aRet;
729 sal_Bool SwMailTransferable::isDataFlavorSupported(
730 const datatransfer::DataFlavor& aFlavor )
731 throw (uno::RuntimeException)
733 return (aFlavor.MimeType == OUString(m_aMimeType));
736 uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( ) throw(uno::RuntimeException)
738 return uno::Reference< beans::XPropertySetInfo >();
741 void SwMailTransferable::setPropertyValue( const OUString& , const uno::Any& )
742 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
743 lang::WrappedTargetException, uno::RuntimeException)
747 uno::Any SwMailTransferable::getPropertyValue( const OUString& rPropertyName )
748 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
750 uno::Any aRet;
751 if ( rPropertyName == "URL" )
752 aRet <<= m_aURL;
753 return aRet;
756 void SwMailTransferable::addPropertyChangeListener(
757 const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
758 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
762 void SwMailTransferable::removePropertyChangeListener(
763 const OUString&,
764 const uno::Reference< beans::XPropertyChangeListener >& )
765 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
769 void SwMailTransferable::addVetoableChangeListener(
770 const OUString&,
771 const uno::Reference< beans::XVetoableChangeListener >& )
772 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
776 void SwMailTransferable::removeVetoableChangeListener(
777 const OUString& ,
778 const uno::Reference< beans::XVetoableChangeListener >& )
779 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
783 SwMailMessage::SwMailMessage() :
784 cppu::WeakComponentImplHelper1< mail::XMailMessage>(m_aMutex)
788 SwMailMessage::~SwMailMessage()
792 OUString SwMailMessage::getSenderName() throw (uno::RuntimeException)
794 return m_sSenderName;
797 OUString SwMailMessage::getSenderAddress() throw (uno::RuntimeException)
799 return m_sSenderAddress;
802 OUString SwMailMessage::getReplyToAddress() throw (uno::RuntimeException)
804 return m_sReplyToAddress;
807 void SwMailMessage::setReplyToAddress( const OUString& _replytoaddress ) throw (uno::RuntimeException)
809 m_sReplyToAddress = _replytoaddress;
812 OUString SwMailMessage::getSubject() throw (uno::RuntimeException)
814 return m_sSubject;
817 void SwMailMessage::setSubject( const OUString& _subject ) throw (uno::RuntimeException)
819 m_sSubject = _subject;
822 uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody() throw (uno::RuntimeException)
824 return m_xBody;
827 void SwMailMessage::setBody(
828 const uno::Reference< datatransfer::XTransferable >& rBody )
829 throw (uno::RuntimeException)
831 m_xBody = rBody;
834 void SwMailMessage::addRecipient( const OUString& rRecipientAddress )
835 throw (uno::RuntimeException)
837 m_aRecipients.realloc(m_aRecipients.getLength() + 1);
838 m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
841 void SwMailMessage::addCcRecipient( const OUString& rRecipientAddress )
842 throw (uno::RuntimeException)
844 m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
845 m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
849 void SwMailMessage::addBccRecipient( const OUString& rRecipientAddress ) throw (uno::RuntimeException)
851 m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
852 m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
855 uno::Sequence< OUString > SwMailMessage::getRecipients( ) throw (uno::RuntimeException)
857 return m_aRecipients;
860 uno::Sequence< OUString > SwMailMessage::getCcRecipients( ) throw (uno::RuntimeException)
862 return m_aCcRecipients;
865 uno::Sequence< OUString > SwMailMessage::getBccRecipients( ) throw (uno::RuntimeException)
867 return m_aBccRecipients;
870 void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
871 throw (uno::RuntimeException)
873 m_aAttachments.realloc(m_aAttachments.getLength() + 1);
874 m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
877 uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
878 throw (uno::RuntimeException)
880 return m_aAttachments;
883 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */