Update ooo320-m1
[ooovba.git] / sw / source / ui / dbui / mailmergehelper.cxx
blob31d8ad42749e8750bbb0eccf884004d25edca428
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mailmergehelper.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <swtypes.hxx>
34 #include <mailmergehelper.hxx>
35 #include <svtools/stdctrl.hxx>
36 #include <mmconfigitem.hxx>
37 #ifndef _DOCSH_HXX
38 #include <docsh.hxx>
39 #endif
40 #include <sfx2/filedlghelper.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/fcontnr.hxx>
44 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
45 #include <com/sun/star/sdb/XColumn.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
48 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
49 #include "com/sun/star/mail/MailServiceProvider.hpp"
50 #include "com/sun/star/mail/XSmtpService.hpp"
51 #include <comphelper/processfactory.hxx>
52 #include <vcl/msgbox.hxx>
53 #ifndef _PASSWD_HXX
54 #include <sfx2/passwd.hxx>
55 #endif
57 #include <dbui.hrc>
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::sdb;
63 using namespace ::com::sun::star::sdbc;
64 using namespace ::com::sun::star::sdbcx;
66 using rtl::OUString;
68 //using ::rtl::OUString;
70 namespace SwMailMergeHelper
73 /*-- 14.06.2004 12:29:19---------------------------------------------------
75 -----------------------------------------------------------------------*/
76 String CallSaveAsDialog(String& rFilter)
78 ErrCode nRet;
79 String sFactory(String::CreateFromAscii(SwDocShell::Factory().GetShortName()));
80 ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
82 sFactory );
84 String sRet;
85 nRet = aDialog.Execute();
86 if(ERRCODE_NONE == nRet)
88 uno::Reference < ui::dialogs::XFilePicker > xFP = aDialog.GetFilePicker();
89 sRet = xFP->getFiles().getConstArray()[0];
90 rFilter = aDialog.GetRealFilter();
92 return sRet;
94 /*-- 20.08.2004 09:39:18---------------------------------------------------
95 simple address check: check for '@'
96 for at least one '.' after the '@'
97 and for at least to characters before and after the dot
98 -----------------------------------------------------------------------*/
99 bool CheckMailAddress( const ::rtl::OUString& rMailAddress )
101 String sAddress(rMailAddress);
102 if(!(sAddress.GetTokenCount('@') == 2))
103 return false;
104 sAddress = sAddress.GetToken(1, '@');
105 if(sAddress.GetTokenCount('.') < 2)
106 return false;
107 if(sAddress.GetToken( 0, '.').Len() < 2 || sAddress.GetToken( 1, '.').Len() < 2)
108 return false;
109 return true;
112 /*-- 28.12.2004 10:16:02---------------------------------------------------
114 -----------------------------------------------------------------------*/
115 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
116 SwMailMergeConfigItem& rConfigItem,
117 uno::Reference< mail::XMailService >& rxInMailService,
118 const String& rInMailServerPassword,
119 const String& rOutMailServerPassword,
120 Window* pDialogParentWindow )
122 uno::Reference< mail::XSmtpService > xSmtpServer;
123 uno::Reference< lang::XMultiServiceFactory> rMgr = ::comphelper::getProcessServiceFactory();
124 if (rMgr.is())
127 uno::Reference< mail::XMailServiceProvider > xMailServiceProvider =
128 mail::MailServiceProvider::create(getCurrentCmpCtx(rMgr));
129 xSmtpServer = uno::Reference< mail::XSmtpService > (
130 xMailServiceProvider->create(
131 mail::MailServiceType_SMTP
132 ), uno::UNO_QUERY);
134 uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
136 if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
138 uno::Reference< mail::XMailService > xInMailService =
139 xMailServiceProvider->create(
140 rConfigItem.IsInServerPOP() ?
141 mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
142 //authenticate at the POP or IMAP server first
143 String sPasswd = rConfigItem.GetInServerPassword();
144 if(rInMailServerPassword.Len())
145 sPasswd = rInMailServerPassword;
146 uno::Reference<mail::XAuthenticator> xAuthenticator =
147 new SwAuthenticator(
148 rConfigItem.GetInServerUserName(),
149 sPasswd,
150 pDialogParentWindow);
152 xInMailService->addConnectionListener(xConnectionListener);
153 //check connection
154 uno::Reference< uno::XCurrentContext> xConnectionContext =
155 new SwConnectionContext(
156 rConfigItem.GetInServerName(),
157 rConfigItem.GetInServerPort(),
158 ::rtl::OUString::createFromAscii( "Insecure" ));
159 xInMailService->connect(xConnectionContext, xAuthenticator);
160 rxInMailService = xInMailService;
162 uno::Reference< mail::XAuthenticator> xAuthenticator;
163 if(rConfigItem.IsAuthentication() &&
164 !rConfigItem.IsSMTPAfterPOP() &&
165 rConfigItem.GetMailUserName().getLength())
167 String sPasswd = rConfigItem.GetMailPassword();
168 if(rOutMailServerPassword.Len())
169 sPasswd = rOutMailServerPassword;
170 xAuthenticator =
171 new SwAuthenticator(rConfigItem.GetMailUserName(),
172 sPasswd,
173 pDialogParentWindow);
175 else
176 xAuthenticator = new SwAuthenticator();
177 //just to check if the server exists
178 xSmtpServer->getSupportedConnectionTypes();
179 //check connection
181 uno::Reference< uno::XCurrentContext> xConnectionContext =
182 new SwConnectionContext(
183 rConfigItem.GetMailServer(),
184 rConfigItem.GetMailPort(),
185 ::rtl::OUString::createFromAscii( rConfigItem.IsSecureConnection() ? "Ssl" : "Insecure"));
186 xSmtpServer->connect(xConnectionContext, xAuthenticator);
187 rxInMailService = uno::Reference< mail::XMailService >( xSmtpServer, uno::UNO_QUERY );
189 catch(uno::Exception& )
191 DBG_ERROR("exception caught");
193 return xSmtpServer;
197 } //namespace
199 /*-- 06.04.2004 10:31:27---------------------------------------------------
201 -----------------------------------------------------------------------*/
202 SwBoldFixedInfo::SwBoldFixedInfo(Window* pParent, const ResId& rResId) :
203 FixedInfo(pParent, rResId)
205 Font aFont = GetFont();
206 aFont.SetWeight( WEIGHT_BOLD );
207 SetFont( aFont );
209 /*-- 06.04.2004 10:31:27---------------------------------------------------
211 -----------------------------------------------------------------------*/
212 SwBoldFixedInfo::~SwBoldFixedInfo()
215 struct SwAddressPreview_Impl
217 ::std::vector< ::rtl::OUString > aAdresses;
218 sal_uInt16 nRows;
219 sal_uInt16 nColumns;
220 sal_uInt16 nSelectedAddress;
221 bool bEnableScrollBar;
223 SwAddressPreview_Impl() :
224 nRows(1),
225 nColumns(1),
226 nSelectedAddress(0),
227 bEnableScrollBar(false)
231 /*-- 27.04.2004 14:01:22---------------------------------------------------
233 -----------------------------------------------------------------------*/
234 SwAddressPreview::SwAddressPreview(Window* pParent, const ResId rResId) :
235 Window( pParent, rResId ),
236 aVScrollBar(this, WB_VSCROLL),
237 pImpl(new SwAddressPreview_Impl())
239 aVScrollBar.SetScrollHdl(LINK(this, SwAddressPreview, ScrollHdl));
240 Size aSize(GetOutputSizePixel());
241 Size aScrollSize(aVScrollBar.GetSizePixel());
242 aScrollSize.Height() = aSize.Height();
243 aVScrollBar.SetSizePixel(aScrollSize);
244 Point aSrollPos(aSize.Width() - aScrollSize.Width(), 0);
245 aVScrollBar.SetPosPixel(aSrollPos);
246 Show();
248 /*-- 27.04.2004 14:01:22---------------------------------------------------
250 -----------------------------------------------------------------------*/
251 SwAddressPreview::~SwAddressPreview()
254 /*-- 25.06.2004 11:50:55---------------------------------------------------
256 -----------------------------------------------------------------------*/
257 IMPL_LINK(SwAddressPreview, ScrollHdl, ScrollBar*, EMPTYARG)
259 Invalidate();
260 return 0;
262 /*-- 27.04.2004 14:01:22---------------------------------------------------
264 -----------------------------------------------------------------------*/
265 void SwAddressPreview::AddAddress(const ::rtl::OUString& rAddress)
267 pImpl->aAdresses.push_back(rAddress);
268 UpdateScrollBar();
270 /*-- 27.04.2004 14:01:23---------------------------------------------------
272 -----------------------------------------------------------------------*/
273 void SwAddressPreview::SetAddress(const ::rtl::OUString& rAddress)
275 pImpl->aAdresses.clear();
276 pImpl->aAdresses.push_back(rAddress);
277 aVScrollBar.Show(FALSE);
278 Invalidate();
280 /*-- 27.04.2004 14:01:23---------------------------------------------------
282 -----------------------------------------------------------------------*/
283 sal_uInt16 SwAddressPreview::GetSelectedAddress()const
285 DBG_ASSERT(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
286 return pImpl->nSelectedAddress;
288 /*-- 25.06.2004 10:32:48---------------------------------------------------
290 -----------------------------------------------------------------------*/
291 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
293 DBG_ASSERT(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
294 pImpl->nSelectedAddress = nSelect;
295 // now make it visible..
296 sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
297 sal_uInt16 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
298 if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
299 aVScrollBar.SetThumbPos( nSelectRow );
301 /*-- 25.06.2004 11:00:40---------------------------------------------------
303 -----------------------------------------------------------------------*/
304 void SwAddressPreview::Clear()
306 pImpl->aAdresses.clear();
307 pImpl->nSelectedAddress = 0;
308 UpdateScrollBar();
310 /*-- 28.04.2004 12:05:50---------------------------------------------------
312 -----------------------------------------------------------------------*/
313 void SwAddressPreview::ReplaceSelectedAddress(const ::rtl::OUString& rNew)
315 pImpl->aAdresses[pImpl->nSelectedAddress] = rNew;
316 Invalidate();
318 /*-- 25.06.2004 11:30:41---------------------------------------------------
320 -----------------------------------------------------------------------*/
321 void SwAddressPreview::RemoveSelectedAddress()
323 pImpl->aAdresses.erase(pImpl->aAdresses.begin() + pImpl->nSelectedAddress);
324 if(pImpl->nSelectedAddress)
325 --pImpl->nSelectedAddress;
326 UpdateScrollBar();
327 Invalidate();
329 /*-- 27.04.2004 14:01:23---------------------------------------------------
331 -----------------------------------------------------------------------*/
332 void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
334 pImpl->nRows = nRows;
335 pImpl->nColumns = nColumns;
336 UpdateScrollBar();
338 /*-- 25.06.2004 13:54:03---------------------------------------------------
340 -----------------------------------------------------------------------*/
341 void SwAddressPreview::EnableScrollBar(bool bEnable)
343 pImpl->bEnableScrollBar = bEnable;
345 /*-- 25.06.2004 11:55:52---------------------------------------------------
347 -----------------------------------------------------------------------*/
348 void SwAddressPreview::UpdateScrollBar()
350 if(pImpl->nColumns)
352 aVScrollBar.SetVisibleSize(pImpl->nRows);
353 sal_uInt16 nResultingRows = (sal_uInt16)(pImpl->aAdresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
354 ++nResultingRows;
355 aVScrollBar.Show(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows);
356 aVScrollBar.SetRange(Range(0, nResultingRows));
357 if(aVScrollBar.GetThumbPos() > nResultingRows)
358 aVScrollBar.SetThumbPos(nResultingRows);
361 /*-- 27.04.2004 14:01:23---------------------------------------------------
363 -----------------------------------------------------------------------*/
364 void SwAddressPreview::Paint(const Rectangle&)
366 const StyleSettings& rSettings = GetSettings().GetStyleSettings();
367 SetFillColor(rSettings.GetWindowColor());
368 SetLineColor( Color(COL_TRANSPARENT) );
369 DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) );
370 Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
371 SetLineColor(aPaintColor);
372 Font aFont(GetFont());
373 aFont.SetColor(aPaintColor);
374 SetFont(aFont);
376 Size aSize = GetOutputSizePixel();
377 sal_uInt16 nStartRow = 0;
378 if(aVScrollBar.IsVisible())
380 aSize.Width() -= aVScrollBar.GetSizePixel().Width();
381 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
383 Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
384 aPartSize.Width() -= 2;
385 aPartSize.Height() -= 2;
387 sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
388 const sal_uInt16 nNumAddresses = static_cast< sal_uInt16 >(pImpl->aAdresses.size());
389 for(sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
391 for(sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
393 if(nAddress >= nNumAddresses)
394 break;
395 Point aPos(nCol * aPartSize.Width(), (nRow) * aPartSize.Height());
396 aPos.Move(1,1);
397 bool bIsSelected = nAddress == pImpl->nSelectedAddress;
398 if((pImpl->nColumns * pImpl->nRows) == 1)
399 bIsSelected = false;
400 ::rtl::OUString adr(pImpl->aAdresses[nAddress]);
401 DrawText_Impl(adr,aPos,aPartSize,bIsSelected);
402 ++nAddress;
405 SetClipRegion();
408 /*-- 07.06.2004 15:44:15---------------------------------------------------
410 -----------------------------------------------------------------------*/
411 void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
413 Window::MouseButtonDown(rMEvt);
414 if(rMEvt.IsLeft() && ( pImpl->nRows || pImpl->nColumns))
416 //determine the selected address
417 const Point& rMousePos = rMEvt.GetPosPixel();
418 Size aSize(GetOutputSizePixel());
419 Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
420 sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
421 if(aVScrollBar.IsVisible())
423 nRow += (sal_uInt16)aVScrollBar.GetThumbPos();
425 sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
426 sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
428 if( nSelect < pImpl->aAdresses.size() &&
429 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
431 pImpl->nSelectedAddress = (sal_uInt16)nSelect;
432 m_aSelectHdl.Call(this);
434 Invalidate();
437 /*-- 01.07.2004 12:33:59---------------------------------------------------
439 -----------------------------------------------------------------------*/
440 void SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
442 USHORT nKey = rKEvt.GetKeyCode().GetCode();
443 if(pImpl->nRows || pImpl->nColumns)
445 sal_uInt32 nSelectedRow = (pImpl->nSelectedAddress + 1)/ pImpl->nColumns;
446 sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress % nSelectedRow;
447 switch(nKey)
449 case KEY_UP:
450 if(nSelectedRow)
451 --nSelectedRow;
452 break;
453 case KEY_DOWN:
454 if(pImpl->aAdresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
455 ++nSelectedRow;
456 break;
457 case KEY_LEFT:
458 if(nSelectedColumn)
459 --nSelectedColumn;
460 break;
461 case KEY_RIGHT:
462 if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
463 pImpl->aAdresses.size() - 1 > pImpl->nSelectedAddress )
464 ++nSelectedColumn;
465 break;
467 sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
468 if( nSelect < pImpl->aAdresses.size() &&
469 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
471 pImpl->nSelectedAddress = (sal_uInt16)nSelect;
472 m_aSelectHdl.Call(this);
473 Invalidate();
476 else
477 Window::KeyInput(rKEvt);
479 /*-- 05.07.2004 12:02:28---------------------------------------------------
481 -----------------------------------------------------------------------*/
482 void SwAddressPreview::StateChanged( StateChangedType nStateChange )
484 if(nStateChange == STATE_CHANGE_ENABLE)
485 Invalidate();
486 Window::StateChanged(nStateChange);
488 /*-- 27.04.2004 14:01:23---------------------------------------------------
490 -----------------------------------------------------------------------*/
491 void SwAddressPreview::DrawText_Impl(
492 const ::rtl::OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected)
494 SetClipRegion( Region( Rectangle(rTopLeft, rSize)) );
495 if(bIsSelected)
497 //selection rectangle
498 SetFillColor(Color(COL_TRANSPARENT));
499 DrawRect(Rectangle(rTopLeft, rSize));
501 sal_Int32 nHeight = GetTextHeight();
502 String sAddress(rAddress);
503 sal_uInt16 nTokens = sAddress.GetTokenCount('\n');
504 Point aStart = rTopLeft;
505 //put it away from the border
506 aStart.Move( 2, 2);
507 for(sal_uInt16 nToken = 0; nToken < nTokens; nToken++)
509 DrawText( aStart, sAddress.GetToken(nToken, '\n') );
510 aStart.Y() += nHeight;
513 /*-- 29.04.2004 11:24:47---------------------------------------------------
515 -----------------------------------------------------------------------*/
516 String SwAddressPreview::FillData(
517 const ::rtl::OUString& rAddress,
518 SwMailMergeConfigItem& rConfigItem,
519 const Sequence< ::rtl::OUString>* pAssignments)
521 //find the column names in the address string (with name assignment!) and
522 //exchange the placeholder (like <Firstname>) with the database content
523 //unassigned columns are expanded to <not assigned>
524 Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
525 Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
526 Sequence< ::rtl::OUString> aAssignment = pAssignments ?
527 *pAssignments :
528 rConfigItem.GetColumnAssignment(
529 rConfigItem.GetCurrentDBData() );
530 const ::rtl::OUString* pAssignment = aAssignment.getConstArray();
531 const ResStringArray& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
532 String sAddress(rAddress);
533 String sNotAssigned(SW_RES(STR_NOTASSIGNED));
534 sNotAssigned.Insert('<', 0);
535 sNotAssigned += '>';
537 sal_Bool bIncludeCountry = rConfigItem.IsIncludeCountry();
538 const ::rtl::OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
539 bool bSpecialReplacementForCountry = (!bIncludeCountry || rExcludeCountry.getLength());
540 String sCountryColumn;
541 if( bSpecialReplacementForCountry )
543 sCountryColumn = rDefHeaders.GetString(MM_PART_COUNTRY);
544 Sequence< ::rtl::OUString> aSpecialAssignment =
545 rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
546 if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
547 sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
550 SwAddressIterator aIter(sAddress);
551 sAddress.Erase();
552 while(aIter.HasMore())
554 SwMergeAddressItem aItem = aIter.Next();
555 if(aItem.bIsColumn)
557 //get the default column name
559 //find the appropriate assignment
560 String sConvertedColumn = aItem.sText;
561 for(USHORT nColumn = 0;
562 nColumn < rDefHeaders.Count() && nColumn < aAssignment.getLength();
563 ++nColumn)
565 if(rDefHeaders.GetString(nColumn) == aItem.sText &&
566 pAssignment[nColumn].getLength())
568 sConvertedColumn = pAssignment[nColumn];
569 break;
572 if(sConvertedColumn.Len() &&
573 xColAccess.is() &&
574 xColAccess->hasByName(sConvertedColumn))
576 //get the content and exchange it in the address string
577 Any aCol = xColAccess->getByName(sConvertedColumn);
578 Reference< XColumn > xColumn;
579 aCol >>= xColumn;
580 if(xColumn.is())
584 ::rtl::OUString sReplace = xColumn->getString();
586 if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
588 if( rExcludeCountry.getLength() && sReplace != rExcludeCountry )
589 aItem.sText = sReplace;
590 else
591 aItem.sText.Erase();
593 else
595 aItem.sText = sReplace;
598 catch( sdbc::SQLException& )
600 DBG_ERROR("SQLException caught");
604 else
606 aItem.sText = sNotAssigned;
610 sAddress += aItem.sText;
612 return sAddress;
615 /*-- 11.05.2004 15:42:08---------------------------------------------------
617 -----------------------------------------------------------------------*/
618 SwMergeAddressItem SwAddressIterator::Next()
620 //currently the string may either start with a '<' then it's a column
621 //otherwise it's simple text maybe containing a return
622 SwMergeAddressItem aRet;
623 if(sAddress.Len())
625 if(sAddress.GetChar(0) == '<')
627 aRet.bIsColumn = true;
628 xub_StrLen nClose = sAddress.Search('>');
629 DBG_ASSERT(nClose != STRING_NOTFOUND, "closing '>' not found");
630 if( nClose != STRING_NOTFOUND )
632 aRet.sText = sAddress.Copy(1, nClose - 1);
633 sAddress.Erase(0, nClose + 1);
635 else
637 aRet.sText = sAddress.Copy(1, 1);
638 sAddress.Erase(0, 1);
641 else
643 xub_StrLen nOpen = sAddress.Search('<');
644 xub_StrLen nReturn = sAddress.Search('\n');
645 if(nReturn == 0)
647 aRet.bIsReturn = true;
648 aRet.sText = '\n';
649 sAddress.Erase(0, 1);
651 else if(STRING_NOTFOUND == nOpen && STRING_NOTFOUND == nReturn)
653 nOpen = sAddress.Len();
654 aRet.sText = sAddress;
655 sAddress.Erase();
657 else
659 xub_StrLen nTarget = ::std::min(nOpen, nReturn);
660 aRet.sText = sAddress.Copy(0, nTarget);
661 sAddress.Erase(0, nTarget);
665 return aRet;
668 /*-- 21.05.2004 10:36:20---------------------------------------------------
670 -----------------------------------------------------------------------*/
671 SwAuthenticator::~SwAuthenticator()
674 /*-- 21.05.2004 10:36:20---------------------------------------------------
676 -----------------------------------------------------------------------*/
677 OUString SwAuthenticator::getUserName( ) throw (RuntimeException)
679 return m_aUserName;
681 /*-- 21.05.2004 10:36:20---------------------------------------------------
683 -----------------------------------------------------------------------*/
684 OUString SwAuthenticator::getPassword( ) throw (RuntimeException)
686 if(m_aUserName.getLength() && !m_aPassword.getLength() && m_pParentWindow)
688 SfxPasswordDialog* pPasswdDlg =
689 new SfxPasswordDialog( m_pParentWindow );
690 pPasswdDlg->SetMinLen( 0 );
691 if(RET_OK == pPasswdDlg->Execute())
692 m_aPassword = pPasswdDlg->GetPassword();
694 return m_aPassword;
696 /*-- 25.08.2004 12:53:03---------------------------------------------------
698 -----------------------------------------------------------------------*/
699 SwConnectionContext::SwConnectionContext(
700 const ::rtl::OUString& rMailServer, sal_Int16 nPort,
701 const ::rtl::OUString& rConnectionType) :
702 m_sMailServer(rMailServer),
703 m_nPort(nPort),
704 m_sConnectionType(rConnectionType)
707 /*-- 25.08.2004 12:53:03---------------------------------------------------
709 -----------------------------------------------------------------------*/
710 SwConnectionContext::~SwConnectionContext()
713 /*-- 25.08.2004 12:53:03---------------------------------------------------
715 -----------------------------------------------------------------------*/
716 uno::Any SwConnectionContext::getValueByName( const ::rtl::OUString& rName )
717 throw (uno::RuntimeException)
719 uno::Any aRet;
720 if( !rName.compareToAscii( "ServerName" ))
721 aRet <<= m_sMailServer;
722 else if( !rName.compareToAscii( "Port" ))
723 aRet <<= (sal_Int32) m_nPort;
724 else if( !rName.compareToAscii( "ConnectionType" ))
725 aRet <<= m_sConnectionType;
726 return aRet;
728 /*-- 21.05.2004 10:45:33---------------------------------------------------
730 -----------------------------------------------------------------------*/
731 SwConnectionListener::~SwConnectionListener()
734 /*-- 21.05.2004 10:45:33---------------------------------------------------
736 -----------------------------------------------------------------------*/
737 void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
738 throw (uno::RuntimeException)
740 //OSL_ENSURE(false, "Connection opened");
742 /*-- 21.05.2004 10:45:33---------------------------------------------------
744 -----------------------------------------------------------------------*/
745 void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
746 throw (uno::RuntimeException)
748 //OSL_ENSURE(false, "Connection closed");
750 /*-- 21.05.2004 10:45:33---------------------------------------------------
752 -----------------------------------------------------------------------*/
753 void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
754 throw(uno::RuntimeException)
757 /*-- 21.05.2004 10:17:22---------------------------------------------------
759 -----------------------------------------------------------------------*/
760 uno::Reference< uno::XComponentContext> getCurrentCmpCtx(
761 uno::Reference<lang::XMultiServiceFactory> rSrvMgr)
763 uno::Reference< beans::XPropertySet > xPropSet =
764 uno::Reference< beans::XPropertySet>(rSrvMgr, uno::UNO_QUERY);
765 Any aAny = xPropSet->getPropertyValue( ::rtl::OUString::createFromAscii("DefaultContext"));
766 uno::Reference< uno::XComponentContext> rCmpCtx;
767 aAny >>= rCmpCtx;
768 return rCmpCtx;
770 /*-- 13.07.2004 09:07:01---------------------------------------------------
772 -----------------------------------------------------------------------*/
773 SwMailTransferable::SwMailTransferable(const rtl::OUString& rBody, const rtl::OUString& rMimeType) :
774 cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
775 m_aMimeType( rMimeType ),
776 m_sBody( rBody ),
777 m_bIsBody( true )
780 /*-- 13.07.2004 09:07:01---------------------------------------------------
782 -----------------------------------------------------------------------*/
783 SwMailTransferable::SwMailTransferable(const rtl::OUString& rURL,
784 const rtl::OUString& rName, const rtl::OUString& rMimeType) :
785 cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
786 m_aMimeType( rMimeType ),
787 m_aURL(rURL),
788 m_aName( rName ),
789 m_bIsBody( false )
792 /*-- 13.07.2004 09:07:08---------------------------------------------------
794 -----------------------------------------------------------------------*/
795 SwMailTransferable::~SwMailTransferable()
798 /*-- 13.07.2004 09:07:08---------------------------------------------------
800 -----------------------------------------------------------------------*/
801 uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
802 throw (datatransfer::UnsupportedFlavorException,
803 io::IOException, uno::RuntimeException)
805 uno::Any aRet;
806 if( m_bIsBody )
807 aRet <<= ::rtl::OUString(m_sBody);
808 else
810 Sequence<sal_Int8> aData;
811 SfxMedium aMedium( m_aURL, STREAM_STD_READ, FALSE );
812 SvStream* pStream = aMedium.GetInStream();
813 if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
815 pStream->Seek(STREAM_SEEK_TO_END);
816 aData.realloc(pStream->Tell());
817 pStream->Seek(0);
818 sal_Int8 * pData = aData.getArray();
819 pStream->Read( pData, aData.getLength() );
821 aRet <<= aData;
823 return aRet;
825 /*-- 13.07.2004 09:07:08---------------------------------------------------
827 -----------------------------------------------------------------------*/
828 uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
829 throw (uno::RuntimeException)
831 uno::Sequence< datatransfer::DataFlavor > aRet(1);
832 aRet[0].MimeType = m_aMimeType;
833 if( m_bIsBody )
835 aRet[0].DataType = getCppuType((::rtl::OUString*)0);
837 else
839 aRet[0].HumanPresentableName = m_aName;
840 aRet[0].DataType = getCppuType((uno::Sequence<sal_Int8>*)0);
842 return aRet;
844 /*-- 13.07.2004 09:07:08---------------------------------------------------
846 -----------------------------------------------------------------------*/
847 sal_Bool SwMailTransferable::isDataFlavorSupported(
848 const datatransfer::DataFlavor& aFlavor )
849 throw (uno::RuntimeException)
851 return (aFlavor.MimeType == ::rtl::OUString(m_aMimeType));
853 /*-- 28.04.2004 09:52:05---------------------------------------------------
855 -----------------------------------------------------------------------*/
856 uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( ) throw(uno::RuntimeException)
858 return uno::Reference< beans::XPropertySetInfo >();
860 /*-- 28.04.2004 09:52:05---------------------------------------------------
862 -----------------------------------------------------------------------*/
863 void SwMailTransferable::setPropertyValue( const ::rtl::OUString& , const uno::Any& )
864 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
865 lang::WrappedTargetException, uno::RuntimeException)
868 /*-- 28.04.2004 09:52:05---------------------------------------------------
870 -----------------------------------------------------------------------*/
871 uno::Any SwMailTransferable::getPropertyValue( const ::rtl::OUString& rPropertyName )
872 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
874 uno::Any aRet;
875 if( rPropertyName.equalsAscii( "URL" ) )
876 aRet <<= m_aURL;
877 return aRet;
879 /*-- 28.04.2004 09:52:05---------------------------------------------------
881 -----------------------------------------------------------------------*/
882 void SwMailTransferable::addPropertyChangeListener(
883 const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
884 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
887 /*-- 28.04.2004 09:52:05---------------------------------------------------
889 -----------------------------------------------------------------------*/
890 void SwMailTransferable::removePropertyChangeListener(
891 const ::rtl::OUString&,
892 const uno::Reference< beans::XPropertyChangeListener >& )
893 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
896 /*-- 28.04.2004 09:52:05---------------------------------------------------
898 -----------------------------------------------------------------------*/
899 void SwMailTransferable::addVetoableChangeListener(
900 const ::rtl::OUString&,
901 const uno::Reference< beans::XVetoableChangeListener >& )
902 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
905 /*-- 28.04.2004 09:52:05---------------------------------------------------
907 -----------------------------------------------------------------------*/
908 void SwMailTransferable::removeVetoableChangeListener(
909 const ::rtl::OUString& ,
910 const uno::Reference< beans::XVetoableChangeListener >& )
911 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
915 /*-- 22.06.2004 16:46:05---------------------------------------------------
917 -----------------------------------------------------------------------*/
918 SwMailMessage::SwMailMessage() :
919 cppu::WeakComponentImplHelper1< mail::XMailMessage>(m_aMutex)
922 /*-- 22.06.2004 16:46:06---------------------------------------------------
924 -----------------------------------------------------------------------*/
925 SwMailMessage::~SwMailMessage()
928 /*-- 02.07.2007 16:00:07---------------------------------------------------
930 -----------------------------------------------------------------------*/
931 ::rtl::OUString SwMailMessage::getSenderName() throw (uno::RuntimeException)
933 return m_sSenderName;
935 /*-- 22.06.2004 16:46:06---------------------------------------------------
937 -----------------------------------------------------------------------*/
938 ::rtl::OUString SwMailMessage::getSenderAddress() throw (uno::RuntimeException)
940 return m_sSenderAddress;
942 /*-- 22.06.2004 16:46:06---------------------------------------------------
944 -----------------------------------------------------------------------*/
945 ::rtl::OUString SwMailMessage::getReplyToAddress() throw (uno::RuntimeException)
947 return m_sReplyToAddress;
949 /*-- 22.06.2004 16:46:07---------------------------------------------------
951 -----------------------------------------------------------------------*/
952 void SwMailMessage::setReplyToAddress( const ::rtl::OUString& _replytoaddress ) throw (uno::RuntimeException)
954 m_sReplyToAddress = _replytoaddress;
956 /*-- 22.06.2004 16:46:07---------------------------------------------------
958 -----------------------------------------------------------------------*/
959 ::rtl::OUString SwMailMessage::getSubject() throw (uno::RuntimeException)
961 return m_sSubject;
963 /*-- 22.06.2004 16:46:07---------------------------------------------------
965 -----------------------------------------------------------------------*/
966 void SwMailMessage::setSubject( const ::rtl::OUString& _subject ) throw (uno::RuntimeException)
968 m_sSubject = _subject;
970 /*-- 13.07.2004 09:57:18---------------------------------------------------
972 -----------------------------------------------------------------------*/
973 uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody() throw (uno::RuntimeException)
975 return m_xBody;
977 /*-- 13.07.2004 09:57:18---------------------------------------------------
979 -----------------------------------------------------------------------*/
980 void SwMailMessage::setBody(
981 const uno::Reference< datatransfer::XTransferable >& rBody )
982 throw (uno::RuntimeException)
984 m_xBody = rBody;
986 /*-- 22.06.2004 16:46:08---------------------------------------------------
988 -----------------------------------------------------------------------*/
989 void SwMailMessage::addRecipient( const ::rtl::OUString& rRecipientAddress )
990 throw (uno::RuntimeException)
992 m_aRecipients.realloc(m_aRecipients.getLength() + 1);
993 m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
995 /*-- 22.06.2004 16:46:09---------------------------------------------------
997 -----------------------------------------------------------------------*/
998 void SwMailMessage::addCcRecipient( const ::rtl::OUString& rRecipientAddress )
999 throw (uno::RuntimeException)
1001 m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
1002 m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
1005 /*-- 22.06.2004 16:46:09---------------------------------------------------
1007 -----------------------------------------------------------------------*/
1008 void SwMailMessage::addBccRecipient( const ::rtl::OUString& rRecipientAddress ) throw (uno::RuntimeException)
1010 m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
1011 m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
1013 /*-- 22.06.2004 16:46:09---------------------------------------------------
1015 -----------------------------------------------------------------------*/
1016 uno::Sequence< ::rtl::OUString > SwMailMessage::getRecipients( ) throw (uno::RuntimeException)
1018 return m_aRecipients;
1020 /*-- 22.06.2004 16:46:10---------------------------------------------------
1022 -----------------------------------------------------------------------*/
1023 uno::Sequence< ::rtl::OUString > SwMailMessage::getCcRecipients( ) throw (uno::RuntimeException)
1025 return m_aCcRecipients;
1027 /*-- 22.06.2004 16:46:10---------------------------------------------------
1029 -----------------------------------------------------------------------*/
1030 uno::Sequence< ::rtl::OUString > SwMailMessage::getBccRecipients( ) throw (uno::RuntimeException)
1032 return m_aBccRecipients;
1034 /*-- 13.07.2004 09:59:48---------------------------------------------------
1036 -----------------------------------------------------------------------*/
1037 void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
1038 throw (uno::RuntimeException)
1040 m_aAttachments.realloc(m_aAttachments.getLength() + 1);
1041 m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
1043 /*-- 13.07.2004 09:59:48---------------------------------------------------
1045 -----------------------------------------------------------------------*/
1046 uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
1047 throw (uno::RuntimeException)
1049 return m_aAttachments;