Bug 1788534 - Use (decrypted) subject from database when composing. r=kaie

Differential Revision: https://phabricator.services.mozilla.com/D188713

--HG--
rename : mail/test/browser/openpgp/browser_editDraftTemplate.js => mail/test/browser/openpgp/composition/browser_editDraftTemplate.js
extra : amend_source : cd21933ed5852c6207228fdd44a8c753b6067753
This commit is contained in:
Magnus Melin 2023-09-22 11:50:20 +02:00
Родитель 38816189c1
Коммит d5d1fef58c
5 изменённых файлов: 48 добавлений и 101 удалений

Просмотреть файл

@ -370,12 +370,7 @@ Enigmail.msg = {
if (self.getSavedDraftOptions(mimeMsg)) {
obtainedDraftFlagsObj.value = true;
}
if (self.draftSubjectEncrypted) {
self.setOriginalSubject(msgHdr.subject, msgHdr.flags, false);
}
updateEncryptionDependencies();
} else if (EnigmailURIs.isEncryptedUri(msgUri)) {
self.setOriginalSubject(msgHdr.subject, msgHdr.flags, false);
}
}
} catch (ex) {
@ -506,85 +501,6 @@ Enigmail.msg = {
return true;
},
/**
* Updates the subject displayed in the #msgSubject element of the compose
* window. Sets prefixes such as "Re" depending on the value gMsgCompose.type.
*
* @param {string} subject The subject for the message.
* @param {number} flags The nsIMsgHdr flags for the message, used to detect
* HasRe on drafts.
* @param {boolean} forceSetting If true, the subject is always updated
* otherwise it is only updated for the following nsIMsgCompTypes: Draft,
* Template,EditTemplate,ForwardInline,ForwardAttachement or EditAsNew.
*/
setOriginalSubject(subject, flags, forceSetting) {
const CT = Ci.nsIMsgCompType;
let subjElem = document.getElementById("msgSubject");
let prefix = "";
let isReply = false;
if (!subjElem) {
return;
}
switch (gMsgCompose.type) {
case CT.ForwardInline:
case CT.ForwardAsAttachment:
prefix =
Services.prefs.getStringPref("mail.forward_subject_prefix") + ": ";
break;
case CT.Draft:
isReply = Boolean(flags & Ci.nsMsgMessageFlags.HasRe);
break;
case CT.Reply:
case CT.ReplyAll:
case CT.ReplyToSender:
case CT.ReplyToGroup:
case CT.ReplyToSenderAndGroup:
case CT.ReplyToList:
isReply = true;
}
if (isReply) {
if (!subject.startsWith("Re: ")) {
prefix = "Re: ";
}
}
let doSetSubject = forceSetting;
switch (gMsgCompose.type) {
case CT.Draft:
case CT.Template:
case CT.EditTemplate:
case CT.ForwardInline:
case CT.ForwardAsAttachment:
case CT.EditAsNew:
doSetSubject = true;
break;
}
if (doSetSubject) {
subject = jsmime.headerparser.decodeRFC2047Words(subject, "utf-8");
if (subjElem.value == "Re: " + subject) {
return;
}
let newSubj = prefix + subject;
if (
newSubj !== subjElem.value ||
newSubj !== gMsgCompose.compFields.subject
) {
gMsgCompose.compFields.subject = newSubj;
subjElem.value = newSubj;
if (typeof subjElem.oninput === "function") {
subjElem.oninput();
}
}
}
},
composeOpen() {
EnigmailLog.DEBUG(
"enigmailMsgComposeOverlay.js: Enigmail.msg.composeOpen\n"

Просмотреть файл

@ -9,7 +9,6 @@ subsuite = thunderbird
support-files = data/**
[browser_collectKeys.js]
[browser_editDraftTemplate.js]
[browser_keyWizard.js]
[browser_openPGPDrafts.js]
[browser_perm_decrypt.js]

Просмотреть файл

@ -18,5 +18,6 @@ skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_P
skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH
[browser_composeSwitchIdentity.js]
skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH
[browser_editDraftTemplate.js]
[browser_expiredKey.js]
skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH

Просмотреть файл

@ -137,10 +137,11 @@ async function doTestSecState(isDraft, secure) {
let cwc = open_compose_new_mail();
let type = isDraft ? "draft" : "template";
let theFolder = isDraft ? draftsFolder : templatesFolder;
let subject = `test ${type}; 🤐; secure=${secure}`;
setup_msg_contents(
cwc,
"test@example.invalid",
`test ${type}; secure=${secure}`,
subject,
`This is a ${type}; secure=${secure}`
);
info(`Testing ${type}; secure=${secure}`);
@ -185,19 +186,31 @@ async function doTestSecState(isDraft, secure) {
);
}
// The double click on col 4 (the subject) should bring up compose window
// for editing this draft.
let draftWindow = await draftWindowPromise;
Assert.equal(
draftWindow.document.getElementById("msgSubject").value,
subject,
"subject should be decrypted"
);
info(`Checking security props in the UI...`);
// @see setEncSigStatusUI()
if (!secure) {
// Wait some to make sure it won't (soon) be showing.
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(resolve => setTimeout(resolve, 100));
Assert.ok(
!draftWindow.document.getElementById("button-encryption").checked,
"should not use encryption"
);
} else {
await TestUtils.waitForCondition(
() => draftWindow.document.getElementById("button-encryption").checked,
"waited for encryption to get turned on"
);
}
draftWindow.close();
clearFolder(theFolder);
}

Просмотреть файл

@ -1596,9 +1596,22 @@ nsresult nsMsgCompose::CreateMessage(const nsACString& originalMsgURI,
reference.Append(messageId);
reference.Append('>');
m_compFields->SetReferences(reference.get());
nsString subject;
msgHdr->GetMime2DecodedSubject(subject);
if (type == nsIMsgCompType::ForwardInline) {
nsCString fwdPrefix;
prefs->GetCharPrefWithDefault("mail.forward_subject_prefix", "Fwd"_ns,
1, fwdPrefix);
nsString unicodeFwdPrefix;
CopyUTF8toUTF16(fwdPrefix, unicodeFwdPrefix);
unicodeFwdPrefix.AppendLiteral(": ");
subject.Insert(unicodeFwdPrefix, 0);
}
m_compFields->SetSubject(subject);
}
// Early return for "Forward inline" and "Reply with template" processing.
// Early return for "ForwardInline" and "ReplyWithTemplate" processing.
return NS_OK;
}
@ -1637,7 +1650,6 @@ nsresult nsMsgCompose::CreateMessage(const nsACString& originalMsgURI,
NS_ENSURE_SUCCESS(rv, rv);
}
if (msgHdr) {
nsCString decodedCString;
nsString subject;
rv = msgHdr->GetMime2DecodedSubject(subject);
if (NS_FAILED(rv)) return rv;
@ -1690,6 +1702,14 @@ nsresult nsMsgCompose::CreateMessage(const nsACString& originalMsgURI,
switch (type) {
default:
break;
case nsIMsgCompType::Draft:
case nsIMsgCompType::Template:
case nsIMsgCompType::EditTemplate:
case nsIMsgCompType::EditAsNew:
// Set subject from db, where it's already decrypted. The raw
// header may be encrypted.
m_compFields->SetSubject(subject);
break;
case nsIMsgCompType::Reply:
case nsIMsgCompType::ReplyAll:
case nsIMsgCompType::ReplyToList:
@ -1777,15 +1797,12 @@ nsresult nsMsgCompose::CreateMessage(const nsACString& originalMsgURI,
if (isFirstPass) {
nsCString fwdPrefix;
prefs->GetCharPref("mail.forward_subject_prefix", fwdPrefix);
if (!fwdPrefix.IsEmpty()) {
nsString unicodeFwdPrefix;
CopyUTF8toUTF16(fwdPrefix, unicodeFwdPrefix);
unicodeFwdPrefix.AppendLiteral(": ");
subject.Insert(unicodeFwdPrefix, 0);
} else {
subject.InsertLiteral(u"Fwd: ", 0);
}
prefs->GetCharPrefWithDefault("mail.forward_subject_prefix",
"Fwd"_ns, 1, fwdPrefix);
nsString unicodeFwdPrefix;
CopyUTF8toUTF16(fwdPrefix, unicodeFwdPrefix);
unicodeFwdPrefix.AppendLiteral(": ");
subject.Insert(unicodeFwdPrefix, 0);
m_compFields->SetSubject(subject);
}
break;
@ -1795,6 +1812,7 @@ nsresult nsMsgCompose::CreateMessage(const nsACString& originalMsgURI,
// original From: header...
nsAutoCString author;
msgHdr->GetAuthor(getter_Copies(author));
m_compFields->SetSubject(subject);
m_compFields->SetReplyTo(author.get());
// ... and empty out the various recipient headers