26#include <com/sun/star/sdbc/SQLException.hpp>
27#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28#include <com/sun/star/sdb/XColumn.hpp>
29#include <com/sun/star/beans/XPropertySet.hpp>
30#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
31#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
32#include <com/sun/star/mail/MailServiceProvider.hpp>
33#include <com/sun/star/mail/XSmtpService.hpp>
61 FileDialogFlags::NONE,
62 SwDocShell::Factory().GetFactoryName(), SfxFilterFlags::NONE, SfxFilterFlags::NONE, pParent);
71 uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDialog.
GetFilePicker();
72 return xFP->getSelectedFiles().getConstArray()[0];
83 const size_t nPosAt = aMailAddress.find(
'@');
84 if (nPosAt == std::u16string_view::npos || aMailAddress.rfind(
'@')!=nPosAt)
86 const size_t nPosDot = aMailAddress.find(
'.', nPosAt);
87 return !(nPosDot==std::u16string_view::npos || nPosDot-nPosAt<2 || aMailAddress.size()-nPosDot<3);
92 uno::Reference< mail::XMailService >& rxInMailService,
93 const OUString& rInMailServerPassword,
94 const OUString& rOutMailServerPassword,
97 uno::Reference< mail::XSmtpService > xSmtpServer;
98 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
101 uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
102 mail::MailServiceProvider::create( xContext ) );
103 xSmtpServer.set(xMailServiceProvider->create(mail::MailServiceType_SMTP), uno::UNO_QUERY);
109 uno::Reference< mail::XMailService > xInMailService =
110 xMailServiceProvider->create(
112 mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
115 if(!rInMailServerPassword.isEmpty())
116 sPasswd = rInMailServerPassword;
117 uno::Reference<mail::XAuthenticator> xAuthenticator =
121 pDialogParentWindow);
123 xInMailService->addConnectionListener(xConnectionListener);
125 uno::Reference< uno::XCurrentContext> xConnectionContext =
130 xInMailService->connect(xConnectionContext, xAuthenticator);
131 rxInMailService = xInMailService;
133 uno::Reference< mail::XAuthenticator> xAuthenticator;
139 if(!rOutMailServerPassword.isEmpty())
140 sPasswd = rOutMailServerPassword;
144 pDialogParentWindow);
149 xSmtpServer->getSupportedConnectionTypes();
152 uno::Reference< uno::XCurrentContext> xConnectionContext =
157 xSmtpServer->connect(xConnectionContext, xAuthenticator);
158 rxInMailService = xSmtpServer;
160 catch (
const uno::Exception&)
187 const OUString& rAddress,
189 const Sequence< OUString>* pAssignments)
194 Reference< XColumnsSupplier > xColsSupp( rConfigItem.
GetResultSet(), UNO_QUERY);
195 Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() :
nullptr;
196 Sequence< OUString> aAssignment = pAssignments ?
200 const OUString* pAssignment = aAssignment.getConstArray();
202 OUString sNotAssigned =
"<" +
SwResId(STR_NOTASSIGNED) +
">";
206 bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
207 OUString sCountryColumn;
208 if( bSpecialReplacementForCountry )
210 sCountryColumn = rDefHeaders[MM_PART_COUNTRY].first;
211 Sequence< OUString> aSpecialAssignment =
213 if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
214 sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
218 OUStringBuffer sAddress;
227 OUString sConvertedColumn = aItem.
sText;
228 auto nSize =
std::min(sal_uInt32(rDefHeaders.size()), sal_uInt32(aAssignment.getLength()));
229 for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
231 if (rDefHeaders[nColumn].
first == aItem.
sText &&
232 !pAssignment[nColumn].isEmpty())
234 sConvertedColumn = pAssignment[nColumn];
238 if(!sConvertedColumn.isEmpty() &&
240 xColAccess->hasByName(sConvertedColumn))
243 Any aCol = xColAccess->getByName(sConvertedColumn);
250 OUString sReplace =
xColumn->getString();
252 if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
254 if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
255 aItem.
sText = sReplace;
261 aItem.
sText = sReplace;
264 catch (
const sdbc::SQLException&)
272 aItem.
sText = sNotAssigned;
276 sAddress.append(aItem.
sText);
278 return sAddress.makeStringAndClear();
283 , m_xVScrollBar(
std::move(xWindow))
299 m_pImpl->aAddresses.push_back(rAddress);
306 m_pImpl->aAddresses.push_back(rAddress);
313 OSL_ENSURE(
m_pImpl->nSelectedAddress <
m_pImpl->aAddresses.size(),
"selection invalid");
314 return m_pImpl->nSelectedAddress;
319 OSL_ENSURE(
m_pImpl->nSelectedAddress <
m_pImpl->aAddresses.size(),
"selection invalid");
320 m_pImpl->nSelectedAddress = nSelect;
322 sal_uInt16 nSelectRow = nSelect /
m_pImpl->nColumns;
323 sal_uInt16 nStartRow =
m_xVScrollBar->vadjustment_get_value();
324 if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow +
m_pImpl->nRows) ))
359 m_pImpl->bEnableScrollBar =
true;
366 sal_uInt16 nResultingRows = o3tl::narrowing<sal_uInt16>(
m_pImpl->aAddresses.size() +
m_pImpl->nColumns - 1) /
m_pImpl->nColumns;
369 if (
nValue > nResultingRows)
371 m_xVScrollBar->set_vpolicy(
m_pImpl->bEnableScrollBar && nResultingRows >
m_pImpl->nRows ? VclPolicyType::ALWAYS : VclPolicyType::NEVER);
391 sal_uInt16 nStartRow = 0;
402 sal_uInt16 nAddress = nStartRow *
m_pImpl->nColumns;
403 const sal_uInt16 nNumAddresses = o3tl::narrowing<sal_uInt16>(
m_pImpl->aAddresses.size());
404 for (sal_uInt16 nRow = 0; nRow <
m_pImpl->nRows ; ++nRow)
406 for (sal_uInt16 nCol = 0; nCol <
m_pImpl->nColumns; ++nCol)
408 if (nAddress >= nNumAddresses)
411 nRow * aPartSize.
Height());
413 bool bIsSelected = nAddress ==
m_pImpl->nSelectedAddress;
416 OUString adr(
m_pImpl->aAddresses[nAddress]);
417 DrawText_Impl(rRenderContext, adr, aPos, aPartSize, bIsSelected);
432 sal_uInt32 nRow = rMousePos.
Y() / aPartSize.
Height() ;
437 sal_uInt32 nCol = rMousePos.
X() / aPartSize.
Width();
438 sal_uInt32 nSelect = nRow *
m_pImpl->nColumns + nCol;
440 if( nSelect < m_pImpl->aAddresses.size() &&
441 m_pImpl->nSelectedAddress != o3tl::narrowing<sal_uInt16>(nSelect))
443 m_pImpl->nSelectedAddress = o3tl::narrowing<sal_uInt16>(nSelect);
454 bool bHandled =
false;
457 sal_uInt32 nSelectedRow =
m_pImpl->nSelectedAddress /
m_pImpl->nColumns;
458 sal_uInt32 nSelectedColumn =
m_pImpl->nSelectedAddress - (nSelectedRow *
m_pImpl->nColumns);
483 sal_uInt32 nSelect = nSelectedRow *
m_pImpl->nColumns + nSelectedColumn;
484 if( nSelect < m_pImpl->aAddresses.size() &&
485 m_pImpl->nSelectedAddress != o3tl::narrowing<sal_uInt16>(nSelect))
487 m_pImpl->nSelectedAddress = o3tl::narrowing<sal_uInt16>(nSelect);
496 const Point& rTopLeft,
const Size& rSize,
bool bIsSelected)
506 Point aStart = rTopLeft;
529 OSL_ENSURE(nClose != -1,
"closing '>' not found");
551 else if(-1 == nOpen && -1 == nReturn)
562 sal_Int32 nTarget =
std::min(nOpen, nReturn);
594 OUString aMailServer, sal_Int16 nPort,
595 OUString aConnectionType) :
596 m_sMailServer(
std::move(aMailServer)),
598 m_sConnectionType(
std::move(aConnectionType))
609 if( rName ==
"ServerName" )
611 else if( rName ==
"Port" )
612 aRet <<= static_cast<sal_Int32>(
m_nPort);
613 else if( rName ==
"ConnectionType" )
636 m_sBody(
std::move( aBody )),
642 OUString aName, OUString aMimeType) :
661 Sequence<sal_Int8>
aData;
678 datatransfer::DataFlavor aRet;
686 aRet.HumanPresentableName =
m_aName;
693 const datatransfer::DataFlavor& aFlavor )
700 return uno::Reference< beans::XPropertySetInfo >();
710 if ( rPropertyName ==
"URL" )
716 const OUString&,
const uno::Reference< beans::XPropertyChangeListener >& )
722 const uno::Reference< beans::XPropertyChangeListener >& )
728 const uno::Reference< beans::XVetoableChangeListener >& )
734 const uno::Reference< beans::XVetoableChangeListener >& )
782 const uno::Reference< datatransfer::XTransferable >& rBody )
const StyleSettings & GetStyleSettings() const
const vcl::KeyCode & GetKeyCode() const
const Point & GetPosPixel() const
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const AllSettings & GetSettings() const
constexpr tools::Long Y() const
void Move(tools::Long nHorzMove, tools::Long nVertMove)
tools::Long AdjustY(tools::Long nVertMove)
constexpr tools::Long X() const
ErrCode GetErrorCode() const
OUString GetPassword() const
virtual short run() override
void SetMinLen(sal_uInt16 Len)
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
tools::Long AdjustWidth(tools::Long n)
constexpr tools::Long Width() const
const Color & GetWindowColor() const
const Color & GetWindowTextColor() const
const Color & GetDisableColor() const
virtual sal_uInt64 TellEnd()
sal_uInt64 Seek(sal_uInt64 nPos)
std::size_t ReadBytes(void *pData, std::size_t nSize)
SwMergeAddressItem Next()
virtual bool KeyInput(const KeyEvent &rKEvt) override
void AddAddress(const OUString &rAddress)
The address string is a list of address elements separated by spaces and breaks.
static OUString FillData(const OUString &rAddress, SwMailMergeConfigItem const &rConfigItem, const css::uno::Sequence< OUString > *pAssignments=nullptr)
std::unique_ptr< SwAddressPreview_Impl > m_pImpl
Link< LinkParamNone *, void > m_aSelectHdl
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
std::unique_ptr< weld::ScrolledWindow > m_xVScrollBar
void DrawText_Impl(vcl::RenderContext &rRenderContext, std::u16string_view rAddress, const Point &rTopLeft, const Size &rSize, bool bIsSelected)
virtual ~SwAddressPreview() override
void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
void SetAddress(const OUString &rAddress)
void SelectAddress(sal_uInt16 nSelect)
sal_uInt16 GetSelectedAddress() const
SwAddressPreview(std::unique_ptr< weld::ScrolledWindow > xParent)
void ReplaceSelectedAddress(const OUString &)
void RemoveSelectedAddress()
virtual OUString SAL_CALL getUserName() override
virtual ~SwAuthenticator() override
virtual OUString SAL_CALL getPassword() override
weld::Window * m_pParentWindow
virtual ~SwConnectionContext() override
virtual css::uno::Any SAL_CALL getValueByName(const OUString &Name) override
OUString m_sConnectionType
SwConnectionContext(OUString aMailServer, sal_Int16 nPort, OUString aConnectionType)
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL disconnected(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL connected(const css::lang::EventObject &aEvent) override
virtual ~SwConnectionListener() override
const SwDBData & GetCurrentDBData() const
OUString const & GetInServerUserName() const
bool IsAuthentication() const
OUString const & GetInServerName() const
OUString const & GetMailServer() const
OUString const & GetMailUserName() const
bool IsIncludeCountry() const
bool IsSecureConnection() const
sal_Int16 GetInServerPort() const
OUString & GetExcludeCountry() const
sal_Int16 GetMailPort() const
bool IsSMTPAfterPOP() const
const std::vector< std::pair< OUString, int > > & GetDefaultAddressHeaders() const
OUString const & GetInServerPassword() const
bool IsInServerPOP() const
OUString const & GetMailPassword() const
css::uno::Sequence< OUString > GetColumnAssignment(const SwDBData &rDBData) const
css::uno::Reference< css::sdbc::XResultSet > const & GetResultSet() const
virtual void SAL_CALL addBccRecipient(const OUString &sRecipientAddress) override
virtual void SAL_CALL setReplyToAddress(const OUString &_replytoaddress) override
virtual css::uno::Sequence< css::mail::MailAttachment > SAL_CALL getAttachments() override
OUString m_sSenderAddress
virtual OUString SAL_CALL getSenderAddress() override
virtual css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getBody() override
css::uno::Sequence< OUString > m_aRecipients
virtual void SAL_CALL setBody(const css::uno::Reference< css::datatransfer::XTransferable > &_body) override
virtual void SAL_CALL addAttachment(const css::mail::MailAttachment &aMailAttachment) override
css::uno::Reference< css::datatransfer::XTransferable > m_xBody
virtual css::uno::Sequence< OUString > SAL_CALL getCcRecipients() override
virtual ~SwMailMessage() override
virtual void SAL_CALL setSubject(const OUString &_subject) override
css::uno::Sequence< OUString > m_aBccRecipients
virtual void SAL_CALL addRecipient(const OUString &sRecipientAddress) override
virtual css::uno::Sequence< OUString > SAL_CALL getRecipients() override
css::uno::Sequence< css::mail::MailAttachment > m_aAttachments
virtual void SAL_CALL addCcRecipient(const OUString &sRecipientAddress) override
virtual OUString SAL_CALL getSubject() override
css::uno::Sequence< OUString > m_aCcRecipients
virtual OUString SAL_CALL getReplyToAddress() override
OUString m_sReplyToAddress
virtual css::uno::Sequence< OUString > SAL_CALL getBccRecipients() override
virtual OUString SAL_CALL getSenderName() override
virtual ~SwMailTransferable() override
virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor &aFlavor) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor &aFlavor) override
SwMailTransferable(OUString aURL, OUString aName, OUString aMimeType)
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
css::uno::Type const & get()
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
OUString GetRealFilter() const
void SetContext(Context _eNewContext)
void SetColor(const Color &)
sal_uInt16 GetCode() const
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define TOOLS_WARN_EXCEPTION(area, stream)
constexpr sal_uInt16 KEY_LEFT
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_RIGHT
constexpr sal_uInt16 KEY_DOWN
#define LINK(Instance, Class, Member)
IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl, weld::ScrolledWindow &, void)
std::unique_ptr< sal_Int32[]> pData
constexpr OUStringLiteral aData
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
OUString CallSaveAsDialog(weld::Window *pParent, OUString &rFilter)
bool CheckMailAddress(std::u16string_view aMailAddress)
constexpr OUStringLiteral first
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
void SetPointFont(OutputDevice &rDevice, const vcl::Font &rFont)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
const sal_Unicode *const aMimeType[]
sal_uInt16 nSelectedAddress
std::vector< OUString > aAddresses
OUString SwResId(TranslateId aId)