1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #include <swtypes.hxx>
27 #include <mailmergehelper.hxx>
28 #include <svtools/stdctrl.hxx>
29 #include <mmconfigitem.hxx>
30 #ifndef _DOCSH_HXX
31 #include <docsh.hxx>
32 #endif
33 #include <sfx2/filedlghelper.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/app.hxx>
36 #include <sfx2/fcontnr.hxx>
37 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
38 #include <com/sun/star/sdb/XColumn.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
41 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
42 #include "com/sun/star/mail/MailServiceProvider.hpp"
43 #include "com/sun/star/mail/XSmtpService.hpp"
44 #include <comphelper/processfactory.hxx>
45 #include <vcl/msgbox.hxx>
46 #ifndef _PASSWD_HXX
47 #include <sfx2/passwd.hxx>
48 #endif
49
50 #include <dbui.hrc>
51
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::container;
55 using namespace ::com::sun::star::sdb;
56 using namespace ::com::sun::star::sdbc;
57 using namespace ::com::sun::star::sdbcx;
58
59 using rtl::OUString;
60
61 //using ::rtl::OUString;
62
63 namespace SwMailMergeHelper
64 {
65
66 /*-- 14.06.2004 12:29:19---------------------------------------------------
67
68 -----------------------------------------------------------------------*/
CallSaveAsDialog(String & rFilter)69 String CallSaveAsDialog(String& rFilter)
70 {
71 ErrCode nRet;
72 String sFactory(String::CreateFromAscii(SwDocShell::Factory().GetShortName()));
73 ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
74 0,
75 sFactory );
76
77 String sRet;
78 nRet = aDialog.Execute();
79 if(ERRCODE_NONE == nRet)
80 {
81 uno::Reference < ui::dialogs::XFilePicker > xFP = aDialog.GetFilePicker();
82 sRet = xFP->getFiles().getConstArray()[0];
83 rFilter = aDialog.GetRealFilter();
84 }
85 return sRet;
86 }
87 /*-- 20.08.2004 09:39:18---------------------------------------------------
88 simple address check: check for '@'
89 for at least one '.' after the '@'
90 and for at least to characters before and after the dot
91 -----------------------------------------------------------------------*/
CheckMailAddress(const::rtl::OUString & rMailAddress)92 bool CheckMailAddress( const ::rtl::OUString& rMailAddress )
93 {
94 String sAddress(rMailAddress);
95 if(!(sAddress.GetTokenCount('@') == 2))
96 return false;
97 sAddress = sAddress.GetToken(1, '@');
98 if(sAddress.GetTokenCount('.') < 2)
99 return false;
100 if(sAddress.GetToken( 0, '.').Len() < 2 || sAddress.GetToken( 1, '.').Len() < 2)
101 return false;
102 return true;
103 }
104
105 /*-- 28.12.2004 10:16:02---------------------------------------------------
106
107 -----------------------------------------------------------------------*/
ConnectToSmtpServer(SwMailMergeConfigItem & rConfigItem,uno::Reference<mail::XMailService> & rxInMailService,const String & rInMailServerPassword,const String & rOutMailServerPassword,Window * pDialogParentWindow)108 uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
109 SwMailMergeConfigItem& rConfigItem,
110 uno::Reference< mail::XMailService >& rxInMailService,
111 const String& rInMailServerPassword,
112 const String& rOutMailServerPassword,
113 Window* pDialogParentWindow )
114 {
115 uno::Reference< mail::XSmtpService > xSmtpServer;
116 uno::Reference< lang::XMultiServiceFactory> rMgr = ::comphelper::getProcessServiceFactory();
117 if (rMgr.is())
118 try
119 {
120 uno::Reference< mail::XMailServiceProvider > xMailServiceProvider =
121 mail::MailServiceProvider::create(getCurrentCmpCtx(rMgr));
122 xSmtpServer = uno::Reference< mail::XSmtpService > (
123 xMailServiceProvider->create(
124 mail::MailServiceType_SMTP
125 ), uno::UNO_QUERY);
126
127 uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
128
129 if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
130 {
131 uno::Reference< mail::XMailService > xInMailService =
132 xMailServiceProvider->create(
133 rConfigItem.IsInServerPOP() ?
134 mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
135 //authenticate at the POP or IMAP server first
136 String sPasswd = rConfigItem.GetInServerPassword();
137 if(rInMailServerPassword.Len())
138 sPasswd = rInMailServerPassword;
139 uno::Reference<mail::XAuthenticator> xAuthenticator =
140 new SwAuthenticator(
141 rConfigItem.GetInServerUserName(),
142 sPasswd,
143 pDialogParentWindow);
144
145 xInMailService->addConnectionListener(xConnectionListener);
146 //check connection
147 uno::Reference< uno::XCurrentContext> xConnectionContext =
148 new SwConnectionContext(
149 rConfigItem.GetInServerName(),
150 rConfigItem.GetInServerPort(),
151 ::rtl::OUString::createFromAscii( "Insecure" ));
152 xInMailService->connect(xConnectionContext, xAuthenticator);
153 rxInMailService = xInMailService;
154 }
155 uno::Reference< mail::XAuthenticator> xAuthenticator;
156 if(rConfigItem.IsAuthentication() &&
157 !rConfigItem.IsSMTPAfterPOP() &&
158 rConfigItem.GetMailUserName().getLength())
159 {
160 String sPasswd = rConfigItem.GetMailPassword();
161 if(rOutMailServerPassword.Len())
162 sPasswd = rOutMailServerPassword;
163 xAuthenticator =
164 new SwAuthenticator(rConfigItem.GetMailUserName(),
165 sPasswd,
166 pDialogParentWindow);
167 }
168 else
169 xAuthenticator = new SwAuthenticator();
170 //just to check if the server exists
171 xSmtpServer->getSupportedConnectionTypes();
172 //check connection
173
174 uno::Reference< uno::XCurrentContext> xConnectionContext =
175 new SwConnectionContext(
176 rConfigItem.GetMailServer(),
177 rConfigItem.GetMailPort(),
178 ::rtl::OUString::createFromAscii( rConfigItem.IsSecureConnection() ? "Ssl" : "Insecure"));
179 xSmtpServer->connect(xConnectionContext, xAuthenticator);
180 rxInMailService = uno::Reference< mail::XMailService >( xSmtpServer, uno::UNO_QUERY );
181 }
182 catch(uno::Exception& )
183 {
184 DBG_ERROR("exception caught");
185 }
186 return xSmtpServer;
187 }
188
189
190 } //namespace
191
192 /*-- 06.04.2004 10:31:27---------------------------------------------------
193
194 -----------------------------------------------------------------------*/
SwBoldFixedInfo(Window * pParent,const ResId & rResId)195 SwBoldFixedInfo::SwBoldFixedInfo(Window* pParent, const ResId& rResId) :
196 FixedInfo(pParent, rResId)
197 {
198 Font aFont = GetFont();
199 aFont.SetWeight( WEIGHT_BOLD );
200 SetFont( aFont );
201 }
202 /*-- 06.04.2004 10:31:27---------------------------------------------------
203
204 -----------------------------------------------------------------------*/
~SwBoldFixedInfo()205 SwBoldFixedInfo::~SwBoldFixedInfo()
206 {
207 }
208 struct SwAddressPreview_Impl
209 {
210 ::std::vector< ::rtl::OUString > aAdresses;
211 sal_uInt16 nRows;
212 sal_uInt16 nColumns;
213 sal_uInt16 nSelectedAddress;
214 bool bEnableScrollBar;
215
SwAddressPreview_ImplSwAddressPreview_Impl216 SwAddressPreview_Impl() :
217 nRows(1),
218 nColumns(1),
219 nSelectedAddress(0),
220 bEnableScrollBar(false)
221 {
222 }
223 };
224 /*-- 27.04.2004 14:01:22---------------------------------------------------
225
226 -----------------------------------------------------------------------*/
SwAddressPreview(Window * pParent,const ResId rResId)227 SwAddressPreview::SwAddressPreview(Window* pParent, const ResId rResId) :
228 Window( pParent, rResId ),
229 aVScrollBar(this, WB_VSCROLL),
230 pImpl(new SwAddressPreview_Impl())
231 {
232 aVScrollBar.SetScrollHdl(LINK(this, SwAddressPreview, ScrollHdl));
233 Size aSize(GetOutputSizePixel());
234 Size aScrollSize(aVScrollBar.GetSizePixel());
235 aScrollSize.Height() = aSize.Height();
236 aVScrollBar.SetSizePixel(aScrollSize);
237 Point aSrollPos(aSize.Width() - aScrollSize.Width(), 0);
238 aVScrollBar.SetPosPixel(aSrollPos);
239 Show();
240 }
241 /*-- 27.04.2004 14:01:22---------------------------------------------------
242
243 -----------------------------------------------------------------------*/
~SwAddressPreview()244 SwAddressPreview::~SwAddressPreview()
245 {
246 }
247 /*-- 25.06.2004 11:50:55---------------------------------------------------
248
249 -----------------------------------------------------------------------*/
IMPL_LINK(SwAddressPreview,ScrollHdl,ScrollBar *,EMPTYARG)250 IMPL_LINK(SwAddressPreview, ScrollHdl, ScrollBar*, EMPTYARG)
251 {
252 Invalidate();
253 return 0;
254 }
255 /*-- 27.04.2004 14:01:22---------------------------------------------------
256
257 -----------------------------------------------------------------------*/
AddAddress(const::rtl::OUString & rAddress)258 void SwAddressPreview::AddAddress(const ::rtl::OUString& rAddress)
259 {
260 pImpl->aAdresses.push_back(rAddress);
261 UpdateScrollBar();
262 }
263 /*-- 27.04.2004 14:01:23---------------------------------------------------
264
265 -----------------------------------------------------------------------*/
SetAddress(const::rtl::OUString & rAddress)266 void SwAddressPreview::SetAddress(const ::rtl::OUString& rAddress)
267 {
268 pImpl->aAdresses.clear();
269 pImpl->aAdresses.push_back(rAddress);
270 aVScrollBar.Show(sal_False);
271 Invalidate();
272 }
273 /*-- 27.04.2004 14:01:23---------------------------------------------------
274
275 -----------------------------------------------------------------------*/
GetSelectedAddress() const276 sal_uInt16 SwAddressPreview::GetSelectedAddress()const
277 {
278 DBG_ASSERT(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
279 return pImpl->nSelectedAddress;
280 }
281 /*-- 25.06.2004 10:32:48---------------------------------------------------
282
283 -----------------------------------------------------------------------*/
SelectAddress(sal_uInt16 nSelect)284 void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
285 {
286 DBG_ASSERT(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
287 pImpl->nSelectedAddress = nSelect;
288 // now make it visible..
289 sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
290 sal_uInt16 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
291 if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
292 aVScrollBar.SetThumbPos( nSelectRow );
293 }
294 /*-- 25.06.2004 11:00:40---------------------------------------------------
295
296 -----------------------------------------------------------------------*/
Clear()297 void SwAddressPreview::Clear()
298 {
299 pImpl->aAdresses.clear();
300 pImpl->nSelectedAddress = 0;
301 UpdateScrollBar();
302 }
303 /*-- 28.04.2004 12:05:50---------------------------------------------------
304
305 -----------------------------------------------------------------------*/
ReplaceSelectedAddress(const::rtl::OUString & rNew)306 void SwAddressPreview::ReplaceSelectedAddress(const ::rtl::OUString& rNew)
307 {
308 pImpl->aAdresses[pImpl->nSelectedAddress] = rNew;
309 Invalidate();
310 }
311 /*-- 25.06.2004 11:30:41---------------------------------------------------
312
313 -----------------------------------------------------------------------*/
RemoveSelectedAddress()314 void SwAddressPreview::RemoveSelectedAddress()
315 {
316 pImpl->aAdresses.erase(pImpl->aAdresses.begin() + pImpl->nSelectedAddress);
317 if(pImpl->nSelectedAddress)
318 --pImpl->nSelectedAddress;
319 UpdateScrollBar();
320 Invalidate();
321 }
322 /*-- 27.04.2004 14:01:23---------------------------------------------------
323
324 -----------------------------------------------------------------------*/
SetLayout(sal_uInt16 nRows,sal_uInt16 nColumns)325 void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
326 {
327 pImpl->nRows = nRows;
328 pImpl->nColumns = nColumns;
329 UpdateScrollBar();
330 }
331 /*-- 25.06.2004 13:54:03---------------------------------------------------
332
333 -----------------------------------------------------------------------*/
EnableScrollBar(bool bEnable)334 void SwAddressPreview::EnableScrollBar(bool bEnable)
335 {
336 pImpl->bEnableScrollBar = bEnable;
337 }
338 /*-- 25.06.2004 11:55:52---------------------------------------------------
339
340 -----------------------------------------------------------------------*/
UpdateScrollBar()341 void SwAddressPreview::UpdateScrollBar()
342 {
343 if(pImpl->nColumns)
344 {
345 aVScrollBar.SetVisibleSize(pImpl->nRows);
346 sal_uInt16 nResultingRows = (sal_uInt16)(pImpl->aAdresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
347 ++nResultingRows;
348 aVScrollBar.Show(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows);
349 aVScrollBar.SetRange(Range(0, nResultingRows));
350 if(aVScrollBar.GetThumbPos() > nResultingRows)
351 aVScrollBar.SetThumbPos(nResultingRows);
352 }
353 }
354 /*-- 27.04.2004 14:01:23---------------------------------------------------
355
356 -----------------------------------------------------------------------*/
Paint(const Rectangle &)357 void SwAddressPreview::Paint(const Rectangle&)
358 {
359 const StyleSettings& rSettings = GetSettings().GetStyleSettings();
360 SetFillColor(rSettings.GetWindowColor());
361 SetLineColor( Color(COL_TRANSPARENT) );
362 DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) );
363 Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
364 SetLineColor(aPaintColor);
365 Font aFont(GetFont());
366 aFont.SetColor(aPaintColor);
367 SetFont(aFont);
368
369 Size aSize = GetOutputSizePixel();
370 sal_uInt16 nStartRow = 0;
371 if(aVScrollBar.IsVisible())
372 {
373 aSize.Width() -= aVScrollBar.GetSizePixel().Width();
374 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
375 }
376 Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
377 aPartSize.Width() -= 2;
378 aPartSize.Height() -= 2;
379
380 sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
381 const sal_uInt16 nNumAddresses = static_cast< sal_uInt16 >(pImpl->aAdresses.size());
382 for(sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
383 {
384 for(sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
385 {
386 if(nAddress >= nNumAddresses)
387 break;
388 Point aPos(nCol * aPartSize.Width(), (nRow) * aPartSize.Height());
389 aPos.Move(1,1);
390 bool bIsSelected = nAddress == pImpl->nSelectedAddress;
391 if((pImpl->nColumns * pImpl->nRows) == 1)
392 bIsSelected = false;
393 ::rtl::OUString adr(pImpl->aAdresses[nAddress]);
394 DrawText_Impl(adr,aPos,aPartSize,bIsSelected);
395 ++nAddress;
396 }
397 }
398 SetClipRegion();
399 }
400
401 /*-- 07.06.2004 15:44:15---------------------------------------------------
402
403 -----------------------------------------------------------------------*/
MouseButtonDown(const MouseEvent & rMEvt)404 void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
405 {
406 Window::MouseButtonDown(rMEvt);
407 if(rMEvt.IsLeft() && ( pImpl->nRows || pImpl->nColumns))
408 {
409 //determine the selected address
410 const Point& rMousePos = rMEvt.GetPosPixel();
411 Size aSize(GetOutputSizePixel());
412 Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
413 sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
414 if(aVScrollBar.IsVisible())
415 {
416 nRow += (sal_uInt16)aVScrollBar.GetThumbPos();
417 }
418 sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
419 sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
420
421 if( nSelect < pImpl->aAdresses.size() &&
422 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
423 {
424 pImpl->nSelectedAddress = (sal_uInt16)nSelect;
425 m_aSelectHdl.Call(this);
426 }
427 Invalidate();
428 }
429 }
430 /*-- 01.07.2004 12:33:59---------------------------------------------------
431
432 -----------------------------------------------------------------------*/
KeyInput(const KeyEvent & rKEvt)433 void SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
434 {
435 sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
436 if(pImpl->nRows || pImpl->nColumns)
437 {
438 sal_uInt32 nSelectedRow = (pImpl->nSelectedAddress + 1)/ pImpl->nColumns;
439 sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress % nSelectedRow;
440 switch(nKey)
441 {
442 case KEY_UP:
443 if(nSelectedRow)
444 --nSelectedRow;
445 break;
446 case KEY_DOWN:
447 if(pImpl->aAdresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
448 ++nSelectedRow;
449 break;
450 case KEY_LEFT:
451 if(nSelectedColumn)
452 --nSelectedColumn;
453 break;
454 case KEY_RIGHT:
455 if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
456 pImpl->aAdresses.size() - 1 > pImpl->nSelectedAddress )
457 ++nSelectedColumn;
458 break;
459 }
460 sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
461 if( nSelect < pImpl->aAdresses.size() &&
462 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
463 {
464 pImpl->nSelectedAddress = (sal_uInt16)nSelect;
465 m_aSelectHdl.Call(this);
466 Invalidate();
467 }
468 }
469 else
470 Window::KeyInput(rKEvt);
471 }
472 /*-- 05.07.2004 12:02:28---------------------------------------------------
473
474 -----------------------------------------------------------------------*/
StateChanged(StateChangedType nStateChange)475 void SwAddressPreview::StateChanged( StateChangedType nStateChange )
476 {
477 if(nStateChange == STATE_CHANGE_ENABLE)
478 Invalidate();
479 Window::StateChanged(nStateChange);
480 }
481 /*-- 27.04.2004 14:01:23---------------------------------------------------
482
483 -----------------------------------------------------------------------*/
DrawText_Impl(const::rtl::OUString & rAddress,const Point & rTopLeft,const Size & rSize,bool bIsSelected)484 void SwAddressPreview::DrawText_Impl(
485 const ::rtl::OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected)
486 {
487 SetClipRegion( Region( Rectangle(rTopLeft, rSize)) );
488 if(bIsSelected)
489 {
490 //selection rectangle
491 SetFillColor(Color(COL_TRANSPARENT));
492 DrawRect(Rectangle(rTopLeft, rSize));
493 }
494 sal_Int32 nHeight = GetTextHeight();
495 String sAddress(rAddress);
496 sal_uInt16 nTokens = sAddress.GetTokenCount('\n');
497 Point aStart = rTopLeft;
498 //put it away from the border
499 aStart.Move( 2, 2);
500 for(sal_uInt16 nToken = 0; nToken < nTokens; nToken++)
501 {
502 DrawText( aStart, sAddress.GetToken(nToken, '\n') );
503 aStart.Y() += nHeight;
504 }
505 }
506 /*-- 29.04.2004 11:24:47---------------------------------------------------
507
508 -----------------------------------------------------------------------*/
FillData(const::rtl::OUString & rAddress,SwMailMergeConfigItem & rConfigItem,const Sequence<::rtl::OUString> * pAssignments)509 String SwAddressPreview::FillData(
510 const ::rtl::OUString& rAddress,
511 SwMailMergeConfigItem& rConfigItem,
512 const Sequence< ::rtl::OUString>* pAssignments)
513 {
514 //find the column names in the address string (with name assignment!) and
515 //exchange the placeholder (like <Firstname>) with the database content
516 //unassigned columns are expanded to <not assigned>
517 Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
518 Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
519 Sequence< ::rtl::OUString> aAssignment = pAssignments ?
520 *pAssignments :
521 rConfigItem.GetColumnAssignment(
522 rConfigItem.GetCurrentDBData() );
523 const ::rtl::OUString* pAssignment = aAssignment.getConstArray();
524 const ResStringArray& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
525 String sAddress(rAddress);
526 String sNotAssigned(SW_RES(STR_NOTASSIGNED));
527 sNotAssigned.Insert('<', 0);
528 sNotAssigned += '>';
529
530 sal_Bool bIncludeCountry = rConfigItem.IsIncludeCountry();
531 const ::rtl::OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
532 bool bSpecialReplacementForCountry = (!bIncludeCountry || rExcludeCountry.getLength());
533 String sCountryColumn;
534 if( bSpecialReplacementForCountry )
535 {
536 sCountryColumn = rDefHeaders.GetString(MM_PART_COUNTRY);
537 Sequence< ::rtl::OUString> aSpecialAssignment =
538 rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
539 if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
540 sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
541 }
542
543 SwAddressIterator aIter(sAddress);
544 sAddress.Erase();
545 while(aIter.HasMore())
546 {
547 SwMergeAddressItem aItem = aIter.Next();
548 if(aItem.bIsColumn)
549 {
550 //get the default column name
551
552 //find the appropriate assignment
553 String sConvertedColumn = aItem.sText;
554 for(sal_uInt16 nColumn = 0;
555 nColumn < rDefHeaders.Count() && nColumn < aAssignment.getLength();
556 ++nColumn)
557 {
558 if(rDefHeaders.GetString(nColumn) == aItem.sText &&
559 pAssignment[nColumn].getLength())
560 {
561 sConvertedColumn = pAssignment[nColumn];
562 break;
563 }
564 }
565 if(sConvertedColumn.Len() &&
566 xColAccess.is() &&
567 xColAccess->hasByName(sConvertedColumn))
568 {
569 //get the content and exchange it in the address string
570 Any aCol = xColAccess->getByName(sConvertedColumn);
571 Reference< XColumn > xColumn;
572 aCol >>= xColumn;
573 if(xColumn.is())
574 {
575 try
576 {
577 ::rtl::OUString sReplace = xColumn->getString();
578
579 if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
580 {
581 if( rExcludeCountry.getLength() && sReplace != rExcludeCountry )
582 aItem.sText = sReplace;
583 else
584 aItem.sText.Erase();
585 }
586 else
587 {
588 aItem.sText = sReplace;
589 }
590 }
591 catch( sdbc::SQLException& )
592 {
593 DBG_ERROR("SQLException caught");
594 }
595 }
596 }
597 else
598 {
599 aItem.sText = sNotAssigned;
600 }
601
602 }
603 sAddress += aItem.sText;
604 }
605 return sAddress;
606 }
607
608 /*-- 11.05.2004 15:42:08---------------------------------------------------
609
610 -----------------------------------------------------------------------*/
Next()611 SwMergeAddressItem SwAddressIterator::Next()
612 {
613 //currently the string may either start with a '<' then it's a column
614 //otherwise it's simple text maybe containing a return
615 SwMergeAddressItem aRet;
616 if(sAddress.Len())
617 {
618 if(sAddress.GetChar(0) == '<')
619 {
620 aRet.bIsColumn = true;
621 xub_StrLen nClose = sAddress.Search('>');
622 DBG_ASSERT(nClose != STRING_NOTFOUND, "closing '>' not found");
623 if( nClose != STRING_NOTFOUND )
624 {
625 aRet.sText = sAddress.Copy(1, nClose - 1);
626 sAddress.Erase(0, nClose + 1);
627 }
628 else
629 {
630 aRet.sText = sAddress.Copy(1, 1);
631 sAddress.Erase(0, 1);
632 }
633 }
634 else
635 {
636 xub_StrLen nOpen = sAddress.Search('<');
637 xub_StrLen nReturn = sAddress.Search('\n');
638 if(nReturn == 0)
639 {
640 aRet.bIsReturn = true;
641 aRet.sText = '\n';
642 sAddress.Erase(0, 1);
643 }
644 else if(STRING_NOTFOUND == nOpen && STRING_NOTFOUND == nReturn)
645 {
646 nOpen = sAddress.Len();
647 aRet.sText = sAddress;
648 sAddress.Erase();
649 }
650 else
651 {
652 xub_StrLen nTarget = ::std::min(nOpen, nReturn);
653 aRet.sText = sAddress.Copy(0, nTarget);
654 sAddress.Erase(0, nTarget);
655 }
656 }
657 }
658 return aRet;
659
660 }
661 /*-- 21.05.2004 10:36:20---------------------------------------------------
662
663 -----------------------------------------------------------------------*/
~SwAuthenticator()664 SwAuthenticator::~SwAuthenticator()
665 {
666 }
667 /*-- 21.05.2004 10:36:20---------------------------------------------------
668
669 -----------------------------------------------------------------------*/
getUserName()670 OUString SwAuthenticator::getUserName( )
671 {
672 return m_aUserName;
673 }
674 /*-- 21.05.2004 10:36:20---------------------------------------------------
675
676 -----------------------------------------------------------------------*/
getPassword()677 OUString SwAuthenticator::getPassword( )
678 {
679 if(m_aUserName.getLength() && !m_aPassword.getLength() && m_pParentWindow)
680 {
681 SfxPasswordDialog* pPasswdDlg =
682 new SfxPasswordDialog( m_pParentWindow );
683 pPasswdDlg->SetMinLen( 0 );
684 if(RET_OK == pPasswdDlg->Execute())
685 m_aPassword = pPasswdDlg->GetPassword();
686 }
687 return m_aPassword;
688 }
689 /*-- 25.08.2004 12:53:03---------------------------------------------------
690
691 -----------------------------------------------------------------------*/
SwConnectionContext(const::rtl::OUString & rMailServer,sal_Int16 nPort,const::rtl::OUString & rConnectionType)692 SwConnectionContext::SwConnectionContext(
693 const ::rtl::OUString& rMailServer, sal_Int16 nPort,
694 const ::rtl::OUString& rConnectionType) :
695 m_sMailServer(rMailServer),
696 m_nPort(nPort),
697 m_sConnectionType(rConnectionType)
698 {
699 }
700 /*-- 25.08.2004 12:53:03---------------------------------------------------
701
702 -----------------------------------------------------------------------*/
~SwConnectionContext()703 SwConnectionContext::~SwConnectionContext()
704 {
705 }
706 /*-- 25.08.2004 12:53:03---------------------------------------------------
707
708 -----------------------------------------------------------------------*/
getValueByName(const::rtl::OUString & rName)709 uno::Any SwConnectionContext::getValueByName( const ::rtl::OUString& rName )
710 {
711 uno::Any aRet;
712 if( !rName.compareToAscii( "ServerName" ))
713 aRet <<= m_sMailServer;
714 else if( !rName.compareToAscii( "Port" ))
715 aRet <<= (sal_Int32) m_nPort;
716 else if( !rName.compareToAscii( "ConnectionType" ))
717 aRet <<= m_sConnectionType;
718 return aRet;
719 }
720 /*-- 21.05.2004 10:45:33---------------------------------------------------
721
722 -----------------------------------------------------------------------*/
~SwConnectionListener()723 SwConnectionListener::~SwConnectionListener()
724 {
725 }
726 /*-- 21.05.2004 10:45:33---------------------------------------------------
727
728 -----------------------------------------------------------------------*/
connected(const lang::EventObject &)729 void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
730 {
731 //OSL_ENSURE(false, "Connection opened");
732 }
733 /*-- 21.05.2004 10:45:33---------------------------------------------------
734
735 -----------------------------------------------------------------------*/
disconnected(const lang::EventObject &)736 void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
737 {
738 //OSL_ENSURE(false, "Connection closed");
739 }
740 /*-- 21.05.2004 10:45:33---------------------------------------------------
741
742 -----------------------------------------------------------------------*/
disposing(const lang::EventObject &)743 void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
744 {
745 }
746 /*-- 21.05.2004 10:17:22---------------------------------------------------
747
748 -----------------------------------------------------------------------*/
getCurrentCmpCtx(uno::Reference<lang::XMultiServiceFactory> rSrvMgr)749 uno::Reference< uno::XComponentContext> getCurrentCmpCtx(
750 uno::Reference<lang::XMultiServiceFactory> rSrvMgr)
751 {
752 uno::Reference< beans::XPropertySet > xPropSet =
753 uno::Reference< beans::XPropertySet>(rSrvMgr, uno::UNO_QUERY);
754 Any aAny = xPropSet->getPropertyValue( ::rtl::OUString::createFromAscii("DefaultContext"));
755 uno::Reference< uno::XComponentContext> rCmpCtx;
756 aAny >>= rCmpCtx;
757 return rCmpCtx;
758 }
759 /*-- 13.07.2004 09:07:01---------------------------------------------------
760
761 -----------------------------------------------------------------------*/
SwMailTransferable(const rtl::OUString & rBody,const rtl::OUString & rMimeType)762 SwMailTransferable::SwMailTransferable(const rtl::OUString& rBody, const rtl::OUString& rMimeType) :
763 cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
764 m_aMimeType( rMimeType ),
765 m_sBody( rBody ),
766 m_bIsBody( true )
767 {
768 }
769 /*-- 13.07.2004 09:07:01---------------------------------------------------
770
771 -----------------------------------------------------------------------*/
SwMailTransferable(const rtl::OUString & rURL,const rtl::OUString & rName,const rtl::OUString & rMimeType)772 SwMailTransferable::SwMailTransferable(const rtl::OUString& rURL,
773 const rtl::OUString& rName, const rtl::OUString& rMimeType) :
774 cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
775 m_aMimeType( rMimeType ),
776 m_aURL(rURL),
777 m_aName( rName ),
778 m_bIsBody( false )
779 {
780 }
781 /*-- 13.07.2004 09:07:08---------------------------------------------------
782
783 -----------------------------------------------------------------------*/
~SwMailTransferable()784 SwMailTransferable::~SwMailTransferable()
785 {
786 }
787 /*-- 13.07.2004 09:07:08---------------------------------------------------
788
789 -----------------------------------------------------------------------*/
getTransferData(const datatransfer::DataFlavor &)790 uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
791 {
792 uno::Any aRet;
793 if( m_bIsBody )
794 aRet <<= ::rtl::OUString(m_sBody);
795 else
796 {
797 Sequence<sal_Int8> aData;
798 SfxMedium aMedium( m_aURL, STREAM_STD_READ, sal_False );
799 SvStream* pStream = aMedium.GetInStream();
800 if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
801 {
802 pStream->Seek(STREAM_SEEK_TO_END);
803 aData.realloc(pStream->Tell());
804 pStream->Seek(0);
805 sal_Int8 * pData = aData.getArray();
806 pStream->Read( pData, aData.getLength() );
807 }
808 aRet <<= aData;
809 }
810 return aRet;
811 }
812 /*-- 13.07.2004 09:07:08---------------------------------------------------
813
814 -----------------------------------------------------------------------*/
getTransferDataFlavors()815 uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
816 {
817 uno::Sequence< datatransfer::DataFlavor > aRet(1);
818 aRet[0].MimeType = m_aMimeType;
819 if( m_bIsBody )
820 {
821 aRet[0].DataType = getCppuType((::rtl::OUString*)0);
822 }
823 else
824 {
825 aRet[0].HumanPresentableName = m_aName;
826 aRet[0].DataType = getCppuType((uno::Sequence<sal_Int8>*)0);
827 }
828 return aRet;
829 }
830 /*-- 13.07.2004 09:07:08---------------------------------------------------
831
832 -----------------------------------------------------------------------*/
isDataFlavorSupported(const datatransfer::DataFlavor & aFlavor)833 sal_Bool SwMailTransferable::isDataFlavorSupported(
834 const datatransfer::DataFlavor& aFlavor )
835 {
836 return (aFlavor.MimeType == ::rtl::OUString(m_aMimeType));
837 }
838 /*-- 28.04.2004 09:52:05---------------------------------------------------
839
840 -----------------------------------------------------------------------*/
getPropertySetInfo()841 uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( )
842 {
843 return uno::Reference< beans::XPropertySetInfo >();
844 }
845 /*-- 28.04.2004 09:52:05---------------------------------------------------
846
847 -----------------------------------------------------------------------*/
setPropertyValue(const::rtl::OUString &,const uno::Any &)848 void SwMailTransferable::setPropertyValue( const ::rtl::OUString& , const uno::Any& )
849 {
850 }
851 /*-- 28.04.2004 09:52:05---------------------------------------------------
852
853 -----------------------------------------------------------------------*/
getPropertyValue(const::rtl::OUString & rPropertyName)854 uno::Any SwMailTransferable::getPropertyValue( const ::rtl::OUString& rPropertyName )
855 {
856 uno::Any aRet;
857 if( rPropertyName.equalsAscii( "URL" ) )
858 aRet <<= m_aURL;
859 return aRet;
860 }
861 /*-- 28.04.2004 09:52:05---------------------------------------------------
862
863 -----------------------------------------------------------------------*/
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)864 void SwMailTransferable::addPropertyChangeListener(
865 const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
866 {
867 }
868 /*-- 28.04.2004 09:52:05---------------------------------------------------
869
870 -----------------------------------------------------------------------*/
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)871 void SwMailTransferable::removePropertyChangeListener(
872 const ::rtl::OUString&,
873 const uno::Reference< beans::XPropertyChangeListener >& )
874 {
875 }
876 /*-- 28.04.2004 09:52:05---------------------------------------------------
877
878 -----------------------------------------------------------------------*/
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)879 void SwMailTransferable::addVetoableChangeListener(
880 const ::rtl::OUString&,
881 const uno::Reference< beans::XVetoableChangeListener >& )
882 {
883 }
884 /*-- 28.04.2004 09:52:05---------------------------------------------------
885
886 -----------------------------------------------------------------------*/
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)887 void SwMailTransferable::removeVetoableChangeListener(
888 const ::rtl::OUString& ,
889 const uno::Reference< beans::XVetoableChangeListener >& )
890 {
891 }
892
893 /*-- 22.06.2004 16:46:05---------------------------------------------------
894
895 -----------------------------------------------------------------------*/
SwMailMessage()896 SwMailMessage::SwMailMessage() :
897 cppu::WeakComponentImplHelper1< mail::XMailMessage>(m_aMutex)
898 {
899 }
900 /*-- 22.06.2004 16:46:06---------------------------------------------------
901
902 -----------------------------------------------------------------------*/
~SwMailMessage()903 SwMailMessage::~SwMailMessage()
904 {
905 }
906 /*-- 02.07.2007 16:00:07---------------------------------------------------
907
908 -----------------------------------------------------------------------*/
getSenderName()909 ::rtl::OUString SwMailMessage::getSenderName()
910 {
911 return m_sSenderName;
912 }
913 /*-- 22.06.2004 16:46:06---------------------------------------------------
914
915 -----------------------------------------------------------------------*/
getSenderAddress()916 ::rtl::OUString SwMailMessage::getSenderAddress()
917 {
918 return m_sSenderAddress;
919 }
920 /*-- 22.06.2004 16:46:06---------------------------------------------------
921
922 -----------------------------------------------------------------------*/
getReplyToAddress()923 ::rtl::OUString SwMailMessage::getReplyToAddress()
924 {
925 return m_sReplyToAddress;
926 }
927 /*-- 22.06.2004 16:46:07---------------------------------------------------
928
929 -----------------------------------------------------------------------*/
setReplyToAddress(const::rtl::OUString & _replytoaddress)930 void SwMailMessage::setReplyToAddress( const ::rtl::OUString& _replytoaddress )
931 {
932 m_sReplyToAddress = _replytoaddress;
933 }
934 /*-- 22.06.2004 16:46:07---------------------------------------------------
935
936 -----------------------------------------------------------------------*/
getSubject()937 ::rtl::OUString SwMailMessage::getSubject()
938 {
939 return m_sSubject;
940 }
941 /*-- 22.06.2004 16:46:07---------------------------------------------------
942
943 -----------------------------------------------------------------------*/
setSubject(const::rtl::OUString & _subject)944 void SwMailMessage::setSubject( const ::rtl::OUString& _subject )
945 {
946 m_sSubject = _subject;
947 }
948 /*-- 13.07.2004 09:57:18---------------------------------------------------
949
950 -----------------------------------------------------------------------*/
getBody()951 uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody()
952 {
953 return m_xBody;
954 }
955 /*-- 13.07.2004 09:57:18---------------------------------------------------
956
957 -----------------------------------------------------------------------*/
setBody(const uno::Reference<datatransfer::XTransferable> & rBody)958 void SwMailMessage::setBody(
959 const uno::Reference< datatransfer::XTransferable >& rBody )
960 {
961 m_xBody = rBody;
962 }
963 /*-- 22.06.2004 16:46:08---------------------------------------------------
964
965 -----------------------------------------------------------------------*/
addRecipient(const::rtl::OUString & rRecipientAddress)966 void SwMailMessage::addRecipient( const ::rtl::OUString& rRecipientAddress )
967 {
968 m_aRecipients.realloc(m_aRecipients.getLength() + 1);
969 m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
970 }
971 /*-- 22.06.2004 16:46:09---------------------------------------------------
972
973 -----------------------------------------------------------------------*/
addCcRecipient(const::rtl::OUString & rRecipientAddress)974 void SwMailMessage::addCcRecipient( const ::rtl::OUString& rRecipientAddress )
975 {
976 m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
977 m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
978
979 }
980 /*-- 22.06.2004 16:46:09---------------------------------------------------
981
982 -----------------------------------------------------------------------*/
addBccRecipient(const::rtl::OUString & rRecipientAddress)983 void SwMailMessage::addBccRecipient( const ::rtl::OUString& rRecipientAddress )
984 {
985 m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
986 m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
987 }
988 /*-- 22.06.2004 16:46:09---------------------------------------------------
989
990 -----------------------------------------------------------------------*/
getRecipients()991 uno::Sequence< ::rtl::OUString > SwMailMessage::getRecipients( )
992 {
993 return m_aRecipients;
994 }
995 /*-- 22.06.2004 16:46:10---------------------------------------------------
996
997 -----------------------------------------------------------------------*/
getCcRecipients()998 uno::Sequence< ::rtl::OUString > SwMailMessage::getCcRecipients( )
999 {
1000 return m_aCcRecipients;
1001 }
1002 /*-- 22.06.2004 16:46:10---------------------------------------------------
1003
1004 -----------------------------------------------------------------------*/
getBccRecipients()1005 uno::Sequence< ::rtl::OUString > SwMailMessage::getBccRecipients( )
1006 {
1007 return m_aBccRecipients;
1008 }
1009 /*-- 13.07.2004 09:59:48---------------------------------------------------
1010
1011 -----------------------------------------------------------------------*/
addAttachment(const mail::MailAttachment & rMailAttachment)1012 void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
1013 {
1014 m_aAttachments.realloc(m_aAttachments.getLength() + 1);
1015 m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
1016 }
1017 /*-- 13.07.2004 09:59:48---------------------------------------------------
1018
1019 -----------------------------------------------------------------------*/
getAttachments()1020 uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
1021 {
1022 return m_aAttachments;
1023 }
1024