using css::uno::UNO_QUERY; using css::uno::Reference; using css::uno::Exception; using css::uno::Sequence; using css::lang::IllegalArgumentException;
using css::system::XSimpleMailClient; using css::system::XSimpleMailMessage; using css::system::XSimpleMailMessage2; using css::system::SimpleMailClientFlags::NO_USER_INTERFACE; using css::system::SimpleMailClientFlags::NO_LOGON_DIALOG;
namespace/* private */
{ /** @internal lookifanalternativeprogramisconfigured
which should be used as senddoc executable */
OUString getAlternativeSenddocUrl()
{
OUString altSenddocUrl; wchar_t buf[EXTENDED_MAX_PATH];
DWORD bufSize(sizeof(buf));
LSTATUS lret = RegGetValueW(HKEY_CURRENT_USER, L"Software\\LibreOffice\\SendAsEMailClient",
nullptr, RRF_RT_REG_SZ, nullptr, buf, &bufSize); if (lret == ERROR_SUCCESS)
osl::FileBase::getFileURLFromSystemPath(OUString(o3tl::toU(buf)), altSenddocUrl); return altSenddocUrl;
}
/* for efficiency reasons we are using a 'bad' cast here asavectororOUStringsisnothingelsethan
an array of pointers to rtl_uString's */
oslProcessError err = osl_executeProcess(
senddocUrl.pData, const_cast<rtl_uString**>(reinterpret_cast<rtl_uString * const *>(rCommandArgs.data())),
rCommandArgs.size(),
nProcOption,
nullptr,
nullptr,
nullptr, 0,
&proc);
namespace { // We cannot use the session-local temporary directory for the attachment, // because it will get removed upon program exit; and it must be alive for // senddoc process lifetime. So we use base temppath for the attachments, // and let the senddoc to do the cleanup if it was started successfully. // This function works like Desktop::CreateTemporaryDirectory()
OUString InitBaseTempDirURL()
{ // No need to intercept an exception here, since // Desktop::CreateTemporaryDirectory() has ensured that path manager is available
SvtPathOptions aOpt;
OUString aRetURL = aOpt.GetTempPath(); if (aRetURL.isEmpty())
{
osl::File::getTempDirURL(aRetURL);
} if (aRetURL.endsWith("/"))
aRetURL = aRetURL.copy(0, aRetURL.getLength() - 1);
OUString CSmplMailClient::CopyAttachment(const OUString& sOrigAttachURL, OUString& sUserVisibleName, bool& nodelete)
{ // We do two things here: // 1. Make the attachment temporary filename to not contain any fancy characters possible in // original filename, that could confuse mailer, and extract the original filename to explicitly // define it; // 2. Allow the copied files be outside of the session's temporary directory, and thus not be // removed in Desktop::RemoveTemporaryDirectory() if soffice process gets closed before the // mailer finishes using them.
maAttachmentFiles.emplace_back(std::make_unique<utl::TempFileNamed>(&GetBaseTempDirURL()));
maAttachmentFiles.back()->EnableKillingFile();
INetURLObject aFilePathObj(maAttachmentFiles.back()->GetURL());
OUString sNewAttachmentURL = aFilePathObj.GetMainURL(INetURLObject::DecodeMechanism::NONE);
OUString sCorrectedOrigAttachURL(sOrigAttachURL); // Make sure to convert to URL, if a system path was passed to XSimpleMailMessage // Ignore conversion error, in which case sCorrectedOrigAttachURL is unchanged
osl::FileBase::getFileURLFromSystemPath(sCorrectedOrigAttachURL, sCorrectedOrigAttachURL); if (osl::File::copy(sCorrectedOrigAttachURL, sNewAttachmentURL) == osl::FileBase::RC::E_None)
{
INetURLObject url(sCorrectedOrigAttachURL, INetURLObject::EncodeMechanism::WasEncoded);
sUserVisibleName = url.getName(INetURLObject::LAST_SEGMENT, true,
INetURLObject::DecodeMechanism::WithCharset);
nodelete = false;
} else
{ // Failed to copy original; the best effort is to use original file. It is possible that // the file gets deleted before used in spawned process; but let's hope... the worst thing // is the absent attachment file anyway.
sNewAttachmentURL = sOrigAttachURL;
maAttachmentFiles.pop_back();
nodelete = true; // Do not delete a non-temporary in senddoc
} return sNewAttachmentURL;
}
void CSmplMailClient::ReleaseAttachments()
{ for (auto& pTempFile : maAttachmentFiles)
{ if (pTempFile)
pTempFile->EnableKillingFile(false);
}
maAttachmentFiles.clear();
}
constbool bWait = aFlag & NO_USER_INTERFACE; if (!executeSenddoc(senddocParams, bWait)) throw Exception( "Send email failed", static_cast<XSimpleMailClient*>(this)); // Let the launched senddoc to cleanup the attachments temporary files if (!bWait)
ReleaseAttachments();
}
void CSmplMailClient::validateParameter( const Reference<XSimpleMailMessage>& xSimpleMailMessage, sal_Int32 aFlag )
{ if (!xSimpleMailMessage.is()) throw IllegalArgumentException( "Empty mail message reference", static_cast<XSimpleMailClient*>(this), 1);
OSL_ENSURE(!(aFlag & NO_LOGON_DIALOG), "Flag NO_LOGON_DIALOG has currently no effect");
// check the flags, the allowed range is 0 - (2^n - 1) if (aFlag < 0 || aFlag > 3) throw IllegalArgumentException( "Invalid flag value", static_cast<XSimpleMailClient*>(this), 2);
// check if a recipient is specified of the flags NO_USER_INTERFACE is specified if ((aFlag & NO_USER_INTERFACE) && !xSimpleMailMessage->getRecipient().getLength()) throw IllegalArgumentException( "No recipient specified", static_cast<XSimpleMailClient*>(this), 1);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.