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

Support for adding favicon by auid or from address #376

Merged
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
18 changes: 12 additions & 6 deletions modules/AuthVerifier.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ var AuthVerifier = {
verify: function _authVerifier_verify(msgHdr, msgURI) {
let promise = (async () => {
// check for saved AuthResult
const msgHeaderParser = Cc["@mozilla.org/messenger/headerparser;1"].createInstance(Ci.nsIMsgHeaderParser);
let savedAuthResult = loadAuthResult(msgHdr);
let author = msgHdr.mime2DecodedAuthor;
let fromAddress = msgHeaderParser.extractHeaderAddressMailboxes(author);
fromAddress = fromAddress.toLowerCase();
if (savedAuthResult) {
return SavedAuthResult_to_AuthResult(savedAuthResult);
return SavedAuthResult_to_AuthResult(savedAuthResult, fromAddress);
}

// get msgURI if not specified
Expand Down Expand Up @@ -182,7 +186,7 @@ var AuthVerifier = {
// save AuthResult
saveAuthResult(msgHdr, savedAuthResult);

let authResult = await SavedAuthResult_to_AuthResult(savedAuthResult);
let authResult = await SavedAuthResult_to_AuthResult(savedAuthResult, fromAddress);
// @ts-ignore
log.debug("authResult: " + authResult.toSource());
return authResult;
Expand Down Expand Up @@ -673,9 +677,10 @@ function dkimSigResultV2_to_AuthResultDKIM(dkimSigResult) { // eslint-disable-li
* Convert SavedAuthResult to AuthResult
*
* @param {SavedAuthResult} savedAuthResult
* @param {String|undefined} from
* @return {Promise<AuthResult>} authResult
*/
async function SavedAuthResult_to_AuthResult(savedAuthResult) { // eslint-disable-line require-await
async function SavedAuthResult_to_AuthResult(savedAuthResult, from) { // eslint-disable-line require-await
/** @type {AuthResult} */
let authResult = savedAuthResult;
authResult.version = "2.1";
Expand All @@ -684,7 +689,7 @@ async function SavedAuthResult_to_AuthResult(savedAuthResult) { // eslint-disabl
authResult.arh.dkim = authResult.arh.dkim.map(
dkimSigResultV2_to_AuthResultDKIM);
}
return addFavicons(authResult);
return addFavicons(authResult, from);
}

/**
Expand All @@ -706,15 +711,16 @@ function AuthResultDKIMV2_to_dkimSigResultV2(authResultDKIM) {
* Add favicons to the DKIM results.
*
* @param {AuthResult} authResult
* @param {String|undefined} from
* @return {Promise<AuthResult>} authResult
*/
async function addFavicons(authResult) {
async function addFavicons(authResult, from) {
if (!prefs.getBoolPref("display.favicon.show")) {
return authResult;
}
for (let i = 0; i < authResult.dkim.length; i++) {
authResult.dkim[i].favicon =
await DKIM.Policy.getFavicon(authResult.dkim[i].sdid);
await DKIM.Policy.getFavicon(authResult.dkim[i].sdid, authResult.dkim[i].auid, from);
}
return authResult;
}
Expand Down
20 changes: 16 additions & 4 deletions modules/dkimPolicy.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -511,21 +511,33 @@ var Policy = {
* Get the URL to the favicon, if available.
*
* @param {String} sdid
* @param {String|undefined} auid
* @param {String|undefined} from
* @return {Promise<String|undefined>} url to favicon
*/
getFavicon: function Policy_getFavicon(sdid) {
getFavicon: function Policy_getFavicon(sdid, auid, from) {
"use strict";

var promise = (async () => {
let promise = (async () => {
if (!favicons) {
var faviconsStr = await readStringFrom("resource://dkim_verifier_data/favicon.json");
let faviconsStr = await readStringFrom("resource://dkim_verifier_data/favicon.json");
favicons = JSON.parse(faviconsStr);
}

var url = favicons[sdid];
// Check if enabled for SDID.
let url = favicons[sdid.toLowerCase()];
if (!url) {
// Check if enabled for the base domain of the SDID.
url = favicons[getBaseDomainFromAddr(sdid)];
}
if (!url && auid) {
// Check if enabled for AUID
url = favicons[auid.toLowerCase()];
}
if (!url && from && addrIsInDomain(from, sdid)) {
// Check if enabled for from
url = favicons[from.toLowerCase()];
}
if (url) {
url = "resource://dkim_verifier_data/favicon/" + url;
}
Expand Down