summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-06-27 12:02:44 +0300
committerGabor Kelemen <kelemeng@ubuntu.com>2022-06-29 11:47:54 +0100
commit859902189d67a85c3172bf0fc4d038fe8611fe82 (patch)
treee5ff819aded0a514e0c656d8d4db7695ab66443b
parent039dd5feae8183088c736f439aacdb366912456b (diff)
tdf#126263: do not try to delete non-temporary files
Change-Id: I5df7db7eac6224fce833e6b9d4ea220cade44e4b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136483 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--shell/source/win32/simplemail/senddoc.cxx38
-rw-r--r--shell/source/win32/simplemail/smplmailclient.cxx10
-rw-r--r--shell/source/win32/simplemail/smplmailclient.hxx2
3 files changed, 35 insertions, 15 deletions
diff --git a/shell/source/win32/simplemail/senddoc.cxx b/shell/source/win32/simplemail/senddoc.cxx
index 3b57684fe821..e34412cbfae1 100644
--- a/shell/source/win32/simplemail/senddoc.cxx
+++ b/shell/source/win32/simplemail/senddoc.cxx
@@ -58,8 +58,8 @@ namespace /* private */
std::vector<std::wstring> gTo;
std::vector<std::wstring> gCc;
std::vector<std::wstring> gBcc;
- // Keep temp filepath and displayed name
- std::vector<std::pair<std::wstring, std::wstring>> gAttachments;
+ // Keep temp filepath, displayed name, and "do not delete" flag
+ std::vector<std::tuple<std::wstring, std::wstring, bool>> gAttachments;
int gMapiFlags = 0;
}
@@ -121,11 +121,12 @@ static void initAttachmentList(MapiAttachmentList_t* pMapiAttachmentList)
{
OSL_ASSERT(pMapiAttachmentList->empty());
- for (const auto& attachment : gAttachments)
+ for (const auto& [filepath, attachname, nodelete] : gAttachments)
{
+ (void)nodelete;
MapiFileDescW mfd;
ZeroMemory(&mfd, sizeof(mfd));
- mfd.lpszPathName = const_cast<wchar_t*>(attachment.first.c_str());
+ mfd.lpszPathName = const_cast<wchar_t*>(filepath.c_str());
// MapiFileDesc documentation (https://msdn.microsoft.com/en-us/library/hh707272)
// allows using here either nullptr, or a pointer to empty string. However,
// for Outlook 2013, we cannot use nullptr here, and must point to a (possibly
@@ -134,7 +135,7 @@ static void initAttachmentList(MapiAttachmentList_t* pMapiAttachmentList)
// Since C++11, c_str() must return a pointer to single null character when the
// string is empty, so we are OK here in case when there's no explicit file name
// passed
- mfd.lpszFileName = const_cast<wchar_t*>(attachment.second.c_str());
+ mfd.lpszFileName = const_cast<wchar_t*>(attachname.c_str());
mfd.nPosition = sal::static_int_cast<ULONG>(-1);
pMapiAttachmentList->push_back(mfd);
}
@@ -239,7 +240,14 @@ static void initParameter(int argc, wchar_t* argv[])
sName = argv[i+3];
i += 2;
}
- gAttachments.emplace_back(sPath, sName);
+ // Also there may be --nodelete to keep the attachment on exit
+ bool nodelete = false;
+ if ((i + 2) < argc && _wcsicmp(argv[i+2], L"--nodelete") == 0)
+ {
+ nodelete = true;
+ ++i;
+ }
+ gAttachments.emplace_back(sPath, sName, nodelete);
}
else if (_wcsicmp(argv[i], L"--langtag") == 0)
gLangTag = o3tl::toU(argv[i+1]);
@@ -401,8 +409,12 @@ int wmain(int argc, wchar_t* argv[])
}
// Now cleanup the temporary attachment files
- for (const auto& rAttachment : gAttachments)
- DeleteFileW(rAttachment.first.c_str());
+ for (const auto& [filepath, attachname, nodelete] : gAttachments)
+ {
+ (void)attachname;
+ if (!nodelete)
+ DeleteFileW(filepath.c_str());
+ }
// Only show the error message if UI was requested
if ((ulRet != SUCCESS_SUCCESS) && (gMapiFlags & (MAPI_DIALOG | MAPI_LOGON_UI)))
@@ -434,11 +446,13 @@ int wmain(int argc, wchar_t* argv[])
for (const auto& address : gBcc)
oss << "--bcc " << address << std::endl;
- for (const auto& attachment : gAttachments)
+ for (const auto& [filepath, attachname, nodelete] : gAttachments)
{
- oss << "--attach " << attachment.first << std::endl;
- if (!attachment.second.empty())
- oss << "--attach-name " << attachment.second << std::endl;
+ oss << "--attach " << filepath << std::endl;
+ if (!attachname.empty())
+ oss << "--attach-name " << attachname << std::endl;
+ if (nodelete)
+ oss << "--nodelete" << std::endl;
}
if (gMapiFlags & MAPI_DIALOG)
diff --git a/shell/source/win32/simplemail/smplmailclient.cxx b/shell/source/win32/simplemail/smplmailclient.cxx
index 4919ded7f889..ff4b7443ef73 100644
--- a/shell/source/win32/simplemail/smplmailclient.cxx
+++ b/shell/source/win32/simplemail/smplmailclient.cxx
@@ -193,7 +193,8 @@ const OUString& GetBaseTempDirURL()
}
}
-OUString CSmplMailClient::CopyAttachment(const OUString& sOrigAttachURL, OUString& sUserVisibleName)
+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
@@ -216,6 +217,7 @@ OUString CSmplMailClient::CopyAttachment(const OUString& sOrigAttachURL, OUStrin
INetURLObject url(sOrigAttachURL, INetURLObject::EncodeMechanism::WasEncoded);
sUserVisibleName = url.getName(INetURLObject::LAST_SEGMENT, true,
INetURLObject::DecodeMechanism::WithCharset);
+ nodelete = false;
}
else
{
@@ -224,6 +226,7 @@ OUString CSmplMailClient::CopyAttachment(const OUString& sOrigAttachURL, OUStrin
// is the absent attachment file anyway.
sNewAttachmentURL = sOrigAttachURL;
maAttachmentFiles.pop_back();
+ nodelete = true; // Do not delete a non-temporary in senddoc
}
return sNewAttachmentURL;
}
@@ -311,7 +314,8 @@ void CSmplMailClient::assembleCommandLine(
for (const auto& attachment : attachments)
{
OUString sDisplayName;
- OUString sTempFileURL(CopyAttachment(attachment, sDisplayName));
+ bool nodelete = false;
+ OUString sTempFileURL(CopyAttachment(attachment, sDisplayName, nodelete));
OUString sysPath;
osl::FileBase::RC err = osl::FileBase::getSystemPathFromFileURL(sTempFileURL, sysPath);
if (err != osl::FileBase::E_None)
@@ -327,6 +331,8 @@ void CSmplMailClient::assembleCommandLine(
rCommandArgs.push_back(ATTACH_NAME);
rCommandArgs.push_back(sDisplayName);
}
+ if (nodelete)
+ rCommandArgs.push_back("--nodelete");
}
if (!(aFlag & NO_USER_INTERFACE))
diff --git a/shell/source/win32/simplemail/smplmailclient.hxx b/shell/source/win32/simplemail/smplmailclient.hxx
index 5844e99147e5..6f71a1a2a715 100644
--- a/shell/source/win32/simplemail/smplmailclient.hxx
+++ b/shell/source/win32/simplemail/smplmailclient.hxx
@@ -38,7 +38,7 @@ public:
private:
void validateParameter(const css::uno::Reference<css::system::XSimpleMailMessage>& xSimpleMailMessage, sal_Int32 aFlag);
void assembleCommandLine(const css::uno::Reference<css::system::XSimpleMailMessage>& xSimpleMailMessage, sal_Int32 aFlag, std::vector<OUString>& rCommandArgs);
- OUString CopyAttachment(const OUString& sOrigAttachURL, OUString& sUserVisibleName);
+ OUString CopyAttachment(const OUString& sOrigAttachURL, OUString& sUserVisibleName, bool& nodelete);
// Don't try to delete the copied attachment files; let the spawned process cleanup them
void ReleaseAttachments();