Skip to content

Commit e8403c3

Browse files
committed
Detect outgoing messages in Locals Folder (#114)
1 parent 340b122 commit e8403c3

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
99
### Enhancements
1010

1111
- Authentication-Results header: Sort DKIM, SPF and DMARC results from ARH, even when not replacing the add-ons verification (#534).
12+
- Detect outgoing messages in Locals Folder (#114).
1213

1314
### Fixes
1415

modules/extensionUtils.mjs.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,16 @@ async function isOutgoing(message, fromAddr) {
8585
return false;
8686
}
8787
// return true if one of the accounts identities contain the from address
88-
const account = await browser.accounts.get(message.folder.accountId);
89-
const identities = account?.identities;
90-
if (identities) {
91-
for (const identity of identities) {
92-
if (fromAddr === identity.email) {
93-
log.debug("email is from own identity, no need fo it to be signed");
94-
return true;
88+
const containingAccount = await browser.accounts.get(message.folder.accountId);
89+
const accounts = containingAccount?.type === "none" ? await browser.accounts.list() : [containingAccount];
90+
for (const account of accounts) {
91+
const identities = account?.identities;
92+
if (identities) {
93+
for (const identity of identities) {
94+
if (fromAddr === identity.email) {
95+
log.debug("email is from own identity, no need fo it to be signed");
96+
return true;
97+
}
9598
}
9699
}
97100
}

test/unittest/extensionUtilsSpec.mjs.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,55 @@ describe("ExtensionUtils [unittest]", function () {
106106
await ExtensionUtils.isOutgoing(createFakeMessageHeader("fakeAccount", undefined), "[email protected]")
107107
).to.be.equal(true);
108108
});
109+
110+
it("For local folder all identities are used", async function () {
111+
const browserAccountsGet = sinon.stub(browser.accounts, "get");
112+
// eslint-disable-next-line require-await
113+
browserAccountsGet.callsFake(async (accountId) => {
114+
if (accountId !== "fakeLocal") {
115+
return null;
116+
}
117+
return {
118+
id: accountId,
119+
identities: [],
120+
name: "A fake local account",
121+
type: "none",
122+
};
123+
});
124+
const browserAccountsList = sinon.stub(browser.accounts, "list");
125+
// eslint-disable-next-line require-await
126+
browserAccountsList.callsFake(async () => {
127+
return [{
128+
id: "fakeLocal",
129+
identities: [],
130+
name: "A fake local account",
131+
type: "none",
132+
}, {
133+
id: "fakeImap",
134+
identities: [
135+
{ email: "[email protected]" },
136+
],
137+
name: "A fake IMAP account",
138+
type: "imap",
139+
}, {
140+
id: "fakePop3",
141+
identities: [
142+
{ email: "[email protected]" },
143+
],
144+
name: "A fake POP3 account",
145+
type: "pop3",
146+
}];
147+
});
148+
149+
expect(
150+
await ExtensionUtils.isOutgoing(createFakeMessageHeader("fakeLocal", undefined), "[email protected]")
151+
).to.be.equal(false);
152+
expect(
153+
await ExtensionUtils.isOutgoing(createFakeMessageHeader("fakeLocal", undefined), "[email protected]")
154+
).to.be.equal(true);
155+
expect(
156+
await ExtensionUtils.isOutgoing(createFakeMessageHeader("fakeLocal", undefined), "[email protected]")
157+
).to.be.equal(true);
158+
});
109159
});
110160
});

0 commit comments

Comments
 (0)