Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #370 from asutherland/activesync-infer-junk-folder
Browse files Browse the repository at this point in the history
Bug 1128883 - [email/activesync] Infer junk folder type from folder name r=jrburke,asuth
  • Loading branch information
jrburke committed Feb 24, 2015
2 parents dc1bdad + 774b830 commit 79683a2
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 8 deletions.
37 changes: 35 additions & 2 deletions js/activesync/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,19 @@ ActiveSyncAccount.prototype = {
12: 'normal', // Mail
},

/**
* List of known junk folder names, taken from browserbox.js, and used to
* infer folders that are junk folders based on their name since there is
* no enumerated type representing junk folders.
*/
_junkFolderNames: [
'bulk mail', 'correo no deseado', 'courrier indésirable', 'istenmeyen',
'istenmeyen e-posta', 'junk', 'levélszemét', 'nevyžiadaná pošta',
'nevyžádaná pošta', 'no deseado', 'posta indesiderata', 'pourriel',
'roskaposti', 'skräppost', 'spam', 'spamowanie', 'søppelpost',
'thư rác', 'спам', 'דואר זבל', 'الرسائل العشوائية', 'هرزنامه', 'สแปม',
'垃圾郵件', '垃圾邮件', '垃圾電郵'],

/**
* Update the internal database and notify the appropriate listeners when we
* discover a new folder.
Expand All @@ -508,7 +521,6 @@ ActiveSyncAccount.prototype = {
if (!forceType && !(typeNum in this._folderTypes))
return true; // Not a folder type we care about.


var path = displayName;
var parentFolderId = null;
var depth = 0;
Expand All @@ -523,6 +535,27 @@ ActiveSyncAccount.prototype = {
depth = parent.$meta.depth + 1;
}

var useFolderType = this._folderTypes[typeNum];
// Check if this looks like a junk folder based on its name/path. (There
// is no type for junk/spam folders, so this regrettably must be inferred
// from the name. At least for hotmail.com/outlook.com, it appears that
// the name is "Junk" regardless of the locale in which the account is
// created, but our current datapoint is one account created using the
// Spanish locale.
//
// In order to avoid bad detections, we assume that the junk folder is
// at the top-level or is only nested one level deep.
if (depth < 2) {
var normalizedName = displayName.toLowerCase();
if (this._junkFolderNames.indexOf(normalizedName) !== -1) {
useFolderType = 'junk';
}
}
if (forceType) {
useFolderType = forceType;
}


// Handle sentinel Inbox.
if (typeNum === $FolderTypes.DefaultInbox) {
var existingInboxMeta = this.getFirstFolderWithType('inbox');
Expand All @@ -546,7 +579,7 @@ ActiveSyncAccount.prototype = {
id: folderId,
serverId: serverId,
name: displayName,
type: forceType || this._folderTypes[typeNum],
type: useFolderType,
path: path,
parentId: parentFolderId,
depth: depth,
Expand Down
9 changes: 3 additions & 6 deletions js/mailapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3774,12 +3774,9 @@ MailAPI.prototype = {
var lowerName = name.toLowerCase();
// Many of the names are the same as the type, but not all.
if ((type === lowerName) ||
(type === 'drafts' && lowerName === 'draft') ||
// yahoo.fr uses 'bulk mail' as its unlocalized name
(type === 'junk' && lowerName === 'bulk mail') ||
(type === 'junk' && lowerName === 'spam') ||
// this is for consistency with Thunderbird
(type === 'queue' && lowerName === 'unsent messages'))
(type === 'drafts') ||
(type === 'junk') ||
(type === 'queue'))
return this.l10n_folder_names[type];
}
return name;
Expand Down
8 changes: 8 additions & 0 deletions test/test-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@
"variants": ["activesync:fake"]
},

"test_activesync_foldersync.js": {
"variants": ["activesync:fake"]
},

"test_activesync_html.js": {
"variants": ["activesync:fake"]
},
Expand Down Expand Up @@ -233,6 +237,10 @@
"variants": ["imap:fake", "imap:real", "activesync:fake", "pop3:fake"]
},

"test_folder_localize.js": {
"variants": ["activesync:fake"]
},

"test_folder_storage.js": {
"variants": ["imap:fake", "imap:real", "activesync:fake", "pop3:fake"]
},
Expand Down
38 changes: 38 additions & 0 deletions test/unit/test_activesync_foldersync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* ActiveSync-specific foldersync logic checks:
* - Make sure the "Junk" folder is identified as having type 'junk'.
*/

define(['rdcommon/testcontext', './resources/th_main',
'activesync/codepages', 'mailapi', 'exports'],
function($tc, $th_main, $ascp, $mailapi, exports) {

var TD = exports.TD = $tc.defineTestsFor(
{ id: 'test_activesync_foldersync' }, null,
[$th_main.TESTHELPER], ['app']);

TD.commonCase('junk folder type gets correctly inferred', function(T, RT) {
T.group('setup');
var TEST_PARAMS = RT.envOptions;
var testUniverse = T.actor('testUniverse', 'U'),
// The fake IMAP server allows folderConfig to be passed as an option.
// It's primarily needed to have an account that lacks specific folders
// from the get-go. Let's do that some day, but for now we'll just
// dynamically create the folder.
testAccount = T.actor('testAccount', 'A',
{ universe: testUniverse }),
eCheck = T.lazyLogger('check');

var junkFolder = testAccount.do_createTestFolder('Junk', { count: 0 });

T.group('check');
T.check(eCheck, 'there better not be a muppet in here', function() {
// do_createTestFolder already uses a ping to ensure the front-end state
// reflects the folder.
eCheck.expect_namedValueD('junk folder type', 'junk');
eCheck.namedValueD('junk folder type',
junkFolder.mailFolder.type, junkFolder.mailFolder);
});
});

});
46 changes: 46 additions & 0 deletions test/unit/test_folder_localize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* ActiveSync-specific foldersync logic checks:
* - Make sure the "Junk" folder is identified as having type 'junk'.
*/

define(['rdcommon/testcontext', './resources/th_main',
'activesync/codepages', 'mailapi', 'exports'],
function($tc, $th_main, $ascp, $mailapi, exports) {

var TD = exports.TD = $tc.defineTestsFor(
{ id: 'test_activesync_foldersync' }, null,
[$th_main.TESTHELPER], ['app']);

TD.commonCase('junk folder type gets correctly localized', function(T, RT) {
T.group('setup');
var TEST_PARAMS = RT.envOptions;
var testUniverse = T.actor('testUniverse', 'U'),
testAccount = T.actor('testAccount', 'A',
{ universe: testUniverse }),
eCheck = T.lazyLogger('check');

var localizedName = 'Sir Junksters III';

T.action('Set up MailAPI.useLocalizedStrings', function() {
testUniverse.MailAPI.useLocalizedStrings({
folderNames: {
junk: localizedName
}
});
});

junkFolder = testAccount.do_createTestFolder('istenmeyen e-posta',
{ count: 0 });

T.group('check');
T.check(eCheck, 'Sir Junksters makes an appearance', function() {
// do_createTestFolder already uses a ping to ensure the front-end state
// reflects the folder.
eCheck.expect_namedValue('localized junk name', localizedName);
eCheck.namedValue('localized junk name', junkFolder.mailFolder.name);
});

T.group('cleanup');
});

});

0 comments on commit 79683a2

Please sign in to comment.