Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further options #45

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions _locales/de-DE/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
"CorrectIdentity.replyFromRecipient": {
"message": "versuchen, die Identität zu suchen und zu benutzen, die in der Empfängerliste erscheint"
},
"CorrectIdentity.keepRecipientAddress": {
"message": "keep the sender address that appears in its recipient list, even if it does not match the identity (e.g., for catch-all adresses)"
},
"CorrectIdentity.removeSenderFromRecipients": {
"message": "remove the identity from the recipient list"
},
"CorrectIdentity.safetyCaption": {
"message": "Sicherheit"
},
Expand Down
6 changes: 6 additions & 0 deletions _locales/en-US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
"CorrectIdentity.replyFromRecipient": {
"message": "attempt to find and use an identity that appears in its recipient list"
},
"CorrectIdentity.keepRecipientAddress": {
"message": "keep the sender address that appears in its recipient list, even if it does not match the identity (e.g., for catch-all adresses)"
},
"CorrectIdentity.removeSenderFromRecipients": {
"message": "remove the identity from the recipient list"
},
"CorrectIdentity.safetyCaption": {
"message": "Safety"
},
Expand Down
6 changes: 6 additions & 0 deletions _locales/fr-FR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"CorrectIdentity.replyFromRecipient": {
"message": "tenter de trouver et d’utiliser une identité qui apparaîtrait dans la liste des destinataires du message."
},
"CorrectIdentity.keepRecipientAddress": {
"message": "keep the sender address that appears in its recipient list, even if it does not match the identity (e.g., for catch-all adresses)"
},
"CorrectIdentity.removeSenderFromRecipients": {
"message": "remove the identity from the recipient list"
},
"CorrectIdentity.safetyCaption": {
"message": "Sécurité"
},
Expand Down
6 changes: 6 additions & 0 deletions _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"CorrectIdentity.replyFromRecipient": {
"message": "返信元のメッセージからアイデンティティの同一性を検出して適用する"
},
"CorrectIdentity.keepRecipientAddress": {
"message": "keep the sender address that appears in its recipient list, even if it does not match the identity (e.g., for catch-all adresses)"
},
"CorrectIdentity.removeSenderFromRecipients": {
"message": "remove the identity from the recipient list"
},
"CorrectIdentity.safetyCaption": {
"message": "安全"
},
Expand Down
6 changes: 6 additions & 0 deletions _locales/nl-NL/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"CorrectIdentity.replyFromRecipient": {
"message": "detecteer en gebruik de identiteit die voorkomt in de ontvangerslijst"
},
"CorrectIdentity.keepRecipientAddress": {
"message": "keep the sender address that appears in its recipient list, even if it does not match the identity (e.g., for catch-all adresses)"
},
"CorrectIdentity.removeSenderFromRecipients": {
"message": "remove the identity from the recipient list"
},
"CorrectIdentity.safetyCaption": {
"message": "Veiligheid"
},
Expand Down
6 changes: 6 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
<div class="box">
<input type="checkbox" id="detectable" name="detectable"
value="detectable"> <label for="detectable">__MSG_CorrectIdentity.identityDetectable__</label><br>
<input type="checkbox"
id="removeSenderFromRecipients" name="removeSenderFromRecipients"
value="removeSenderFromRecipients"> <label for="removeSenderFromRecipients" id="removeSenderFromRecipientsLabel">__MSG_CorrectIdentity.removeSenderFromRecipients__</label><br>
<input type="checkbox"
id="keepRecipientAddress" name="keepRecipientAddress"
value="keepRecipientAddress"> <label for="keepRecipientAddress" id="keepRecipientAddressLabel">__MSG_CorrectIdentity.keepRecipientAddress__</label><br>
</div>
<label for="detectionAliases">__MSG_CorrectIdentity.aliasesDescription__</label>
<div class="tooltip">
Expand Down
42 changes: 34 additions & 8 deletions scripts/background-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let guiState = {

let settings = {
accountSettings: {}, // key: accountId; values: identityMechanism, explicitIdentity, replyFromRecipient
identitySettings: {}, // key: identityId; values: detectable, detectionAliases, warningAliases
identitySettings: {}, // key: identityId; values: detectable, keepRecipientAddress, removeSenderFromRecipients, detectionAliases, warningAliases
// migrate ... property will be dynamically added if old prefs were migrated
additionalHeaderFields: []
};
Expand Down Expand Up @@ -122,6 +122,12 @@ function checkSettings(inSettings) {
if (is.detectable === undefined) {
is.detectable = true;
}
if (is.keepRecipientAddress === undefined) {
is.keepRecipientAddress = false;
}
if (is.removeSenderFromRecipients === undefined) {
is.removeSenderFromRecipients = true;
}
if (is.detectionAliases === undefined) {
is.detectionAliases = "";
}
Expand Down Expand Up @@ -608,16 +614,36 @@ async function handleComposeTabChanged(tabId, initialIdentityId, currentIdentity
identityId : newIdentityId,
};

// Check if newIdentityId was in "to", "cc" or "cc". Remove it from there
// Use custom original sender address if Identity Email is not equal to Original Recipient Email (first entry of the list)
// Plus: Check if newIdentityId was in "to", "cc" or "cc". Remove it from there
// Both: If configured, respect the settings.
try {
let newIdentity = await messenger.identities.get(newIdentityId);
let newIdentityEmail = newIdentity.email;
if (searchAndRemoveFromRecipientList(composeTabStatus[tabId].toRecipientsList, newIdentityEmail)) {
// found in "to"
details.to = composeTabStatus[tabId].toRecipientsList;
} else if (searchAndRemoveFromRecipientList(composeTabStatus[tabId].ccRecipientsList, newIdentityEmail)) {
// found in "cc"
details.cc = composeTabStatus[tabId].ccRecipientsList;
let perIdentitySettings = settings.identitySettings[newIdentityId];

if (perIdentitySettings.keepRecipientAddress) {
// Keep original sender address (first entry of the list)
let origRecipientEmail = origRecipientsList[0];
if (newIdentityEmail !== origRecipientEmail) {
console.log("newIdentityEmail: ", newIdentityEmail);
console.log("origRecipientEmail: ", origRecipientEmail);
console.log("Mismatch! Setting sender email to origRecipientEmail (" + origRecipientEmail + ")");

details.from = newIdentity.name +' <'+ origRecipientEmail + '>';
newIdentityEmail = origRecipientEmail;
}
}

if (perIdentitySettings.removeSenderFromRecipients) {
// remove sender address from recipients
if (searchAndRemoveFromRecipientList(composeTabStatus[tabId].toRecipientsList, newIdentityEmail)) {
// found in "to"
details.to = composeTabStatus[tabId].toRecipientsList;
} else if (searchAndRemoveFromRecipientList(composeTabStatus[tabId].ccRecipientsList, newIdentityEmail)) {
// found in "cc"
details.cc = composeTabStatus[tabId].ccRecipientsList;
}
}

messenger.compose.setComposeDetails(tabId, details);
Expand Down
31 changes: 29 additions & 2 deletions scripts/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function getPerIdentitySettingsOrDefault(identityId) {
if (perIdentitySettings === undefined) {
// not found in settings, set defaults
perIdentitySettings = {
detectable: true,
detectable, removeSenderFromRecipients: true,
keepRecipientAddress: false,
detectionAliases: "",
warningAliases: "",
};
Expand Down Expand Up @@ -122,6 +123,10 @@ function updateGuiDetectionIdentityChanged(newDetectionIdentityId) {

document.getElementById("detectable").checked =
perIdentitySettings.detectable;
document.getElementById("removeSenderFromRecipients").checked =
perIdentitySettings.removeSenderFromRecipients;
document.getElementById("keepRecipientAddress").checked =
perIdentitySettings.keepRecipientAddress;
document.getElementById("detectionAliases").value =
perIdentitySettings.detectionAliases;
}
Expand All @@ -138,7 +143,7 @@ function updateAdditionalHeaderFields() {
let str = "";
for (let i=0; i< settings.additionalHeaderFields.length; i++) {
// key value
str = settings.additionalHeaderFields[i][0];
str += settings.additionalHeaderFields[i][0];

// occurence value
if (settings.additionalHeaderFields[i][1]) {
Expand Down Expand Up @@ -242,6 +247,22 @@ function detectableChanged(result) {
notifySettingsChanged();
}

function keepRecipientAddressChanged(result) {
let perIdentitySettings = getPerIdentitySettingsOrDefault(
guiState.currentDetectionIdentity
);
perIdentitySettings.keepRecipientAddress = result.target.checked;
notifySettingsChanged();
}

function removeSenderFromRecipientsChanged(result) {
let perIdentitySettings = getPerIdentitySettingsOrDefault(
guiState.currentDetectionIdentity
);
perIdentitySettings.removeSenderFromRecipients = result.target.checked;
notifySettingsChanged();
}

function detectionAliasesChanged(result) {
let perIdentitySettings = getPerIdentitySettingsOrDefault(
guiState.currentDetectionIdentity
Expand Down Expand Up @@ -298,6 +319,12 @@ function installConfigPageEventListners() {
document
.getElementById("detectable")
.addEventListener("change", detectableChanged);
document
.getElementById("keepRecipientAddress")
.addEventListener("change", keepRecipientAddressChanged);
document
.getElementById("removeSenderFromRecipients")
.addEventListener("change", removeSenderFromRecipientsChanged);
document
.getElementById("detectionAliases")
.addEventListener("change", detectionAliasesChanged);
Expand Down