]> git.donarmstrong.com Git - dactyl.git/blobdiff - teledactyl/content/mail.js
Import r6976 from upstream hg supporting Firefox up to 25.*
[dactyl.git] / teledactyl / content / mail.js
index ff01820c6eb57555861fae186f3cf972644c8612..0daace8b28ec11587b08a25ac88827a66a91509e 100644 (file)
@@ -4,7 +4,7 @@
 // given in the LICENSE.txt file included with this file.
 "use strict";
 
-const Mail = Module("mail", {
+var Mail = Module("mail", {
     init: function init() {
         // used for asynchronously selecting messages after wrapping folders
         this._selectMessageKeys = [];
@@ -70,9 +70,9 @@ const Mail = Module("mail", {
     _moveOrCopy: function (copy, destinationFolder, operateOnThread) {
         let folders = mail.getFolders(destinationFolder);
         if (folders.length == 0)
-            return void dactyl.echoerr("Exxx: No matching folder for " + destinationFolder);
+            return void dactyl.echoerr(_("addressbook.noMatchingFolder", destinationFolder));
         else if (folders.length > 1)
-            return dactyl.echoerr("Exxx: More than one match for " + destinationFolder);
+            return dactyl.echoerr(_("addressbook.multipleFolderMatches", destinationFolder));
 
         let count = gDBView.selection.count;
         if (!count)
@@ -129,7 +129,7 @@ const Mail = Module("mail", {
 
     get currentFolder() gFolderTreeView.getSelectedFolders()[0],
 
-    /** @property {nsISmtpServer[]} The list of configured SMTP servers. */
+    /** @property {[nsISmtpServer]} The list of configured SMTP servers. */
     get smtpServers() {
         let servers = services.smtp.smtpServers;
         let res = [];
@@ -168,7 +168,7 @@ const Mail = Module("mail", {
                     let url = args.attachments.pop();
                     let file = io.getFile(url);
                     if (!file.exists())
-                        return void dactyl.echoerr("Exxx: Could not attach file `" + url + "'", commandline.FORCE_SINGLELINE);
+                        return void dactyl.echoerr(_("mail.cantAttachFile", url), commandline.FORCE_SINGLELINE);
 
                     attachment = Cc["@mozilla.org/messengercompose/attachment;1"].createInstance(Ci.nsIMsgAttachment);
                     attachment.url = "file://" + file.path;
@@ -179,9 +179,7 @@ const Mail = Module("mail", {
 
         params.type = Ci.nsIMsgCompType.New;
 
-        const msgComposeService = Cc["@mozilla.org/messengercompose;1"].getService();
-        msgComposeService = msgComposeService.QueryInterface(Ci.nsIMsgComposeService);
-        msgComposeService.OpenComposeWindowWithParams(null, params);
+        services.compose.OpenComposeWindowWithParams(null, params);
     },
 
     // returns an array of nsIMsgFolder objects
@@ -402,7 +400,7 @@ const Mail = Module("mail", {
 
                 let folder = mail.getFolders(arg, true, true)[count];
                 if (!folder)
-                    dactyl.echoerr("Exxx: Folder \"" + arg + "\" does not exist");
+                    dactyl.echoerr(_("command.goto.folderNotExist", arg));
                 else if (dactyl.forceNewTab)
                     MsgOpenNewTabForFolder(folder.URI);
                 else
@@ -433,8 +431,8 @@ const Mail = Module("mail", {
                     addresses = addresses.concat(mailargs.cc);
 
                 // TODO: is there a better way to check for validity?
-                if (addresses.some(function (recipient) !(/\S@\S+\.\S/.test(recipient))))
-                    return void dactyl.echoerr("Exxx: Invalid e-mail address");
+                if (addresses.some(recipient => !(/\S@\S+\.\S/.test(recipient))))
+                    return void dactyl.echoerr(_("command.mail.invalidEmailAddress"));
 
                 mail.composeNewMail(mailargs);
             },
@@ -453,7 +451,7 @@ const Mail = Module("mail", {
             "Copy selected messages",
             function (args) { mail._moveOrCopy(true, args.literalArg); },
             {
-                argCount: 1,
+                argCount: "1",
                 completer: function (context) completion.mailFolder(context),
                 literal: 0
             });
@@ -462,7 +460,7 @@ const Mail = Module("mail", {
             "Move selected messages",
             function (args) { mail._moveOrCopy(false, args.literalArg); },
             {
-                argCount: 1,
+                argCount: "1",
                 completer: function (context) completion.mailFolder(context),
                 literal: 0
             });
@@ -474,7 +472,7 @@ const Mail = Module("mail", {
 
         commands.add(["get[messages]"],
             "Check for new messages",
-            function (args) mail.getNewMessages(!args.bang),
+            function (args) { mail.getNewMessages(!args.bang); },
             {
                 argCount: "0",
                 bang: true,
@@ -485,7 +483,7 @@ const Mail = Module("mail", {
             let folders = mail.getFolders(context.filter);
             context.anchored = false;
             context.quote = false;
-            context.completions = folders.map(function (folder)
+            context.completions = folders.map(folder =>
                     [folder.server.prettyName + ": " + folder.name,
                      "Unread: " + folder.getNumUnread(false)]);
         };
@@ -508,7 +506,7 @@ const Mail = Module("mail", {
 
         mappings.add(myModes, ["<Space>"],
             "Scroll message or select next unread one",
-            function () Events.PASS);
+            () => Events.PASS);
 
         mappings.add(myModes, ["t"],
             "Select thread",
@@ -520,47 +518,47 @@ const Mail = Module("mail", {
 
         mappings.add(myModes, ["j", "<Right>"],
             "Select next message",
-            function (args) { mail.selectMessage(function (msg) true, false, false, false, args.count); },
+            function ({ count }) { mail.selectMessage(msg => true, false, false, false, count); },
             { count: true });
 
         mappings.add(myModes, ["gj"],
             "Select next message, including closed threads",
-            function (args) { mail.selectMessage(function (msg) true, false, true, false, args.count); },
+            function ({ count }) { mail.selectMessage(msg => true, false, true, false, count); },
             { count: true });
 
         mappings.add(myModes, ["J", "<Tab>"],
             "Select next unread message",
-            function (args) { mail.selectMessage(function (msg) !msg.isRead, true, true, false, args.count); },
+            function ({ count }) { mail.selectMessage(msg => !msg.isRead, true, true, false, count); },
             { count: true });
 
         mappings.add(myModes, ["k", "<Left>"],
             "Select previous message",
-            function (args) { mail.selectMessage(function (msg) true, false, false, true, args.count); },
+            function ({ count }) { mail.selectMessage(msg => true, false, false, true, count); },
             { count: true });
 
         mappings.add(myModes, ["gk"],
             "Select previous message",
-            function (args) { mail.selectMessage(function (msg) true, false, true, true, args.count); },
+            function ({ count }) { mail.selectMessage(msg => true, false, true, true, count); },
             { count: true });
 
         mappings.add(myModes, ["K"],
             "Select previous unread message",
-            function (args) { mail.selectMessage(function (msg) !msg.isRead, true, true, true, args.count); },
+            function ({ count }) { mail.selectMessage(msg => !msg.isRead, true, true, true, count); },
             { count: true });
 
         mappings.add(myModes, ["*"],
             "Select next message from the same sender",
-            function (args) {
+            function ({ count }) {
                 let author = gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor.toLowerCase();
-                mail.selectMessage(function (msg) msg.mime2DecodedAuthor.toLowerCase().indexOf(author) == 0, true, true, false, args.count);
+                mail.selectMessage(msg => msg.mime2DecodedAuthor.toLowerCase().indexOf(author) == 0, true, true, false, count);
             },
             { count: true });
 
         mappings.add(myModes, ["#"],
             "Select previous message from the same sender",
-            function (args) {
+            function ({ count }) {
                 let author = gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor.toLowerCase();
-                mail.selectMessage(function (msg) msg.mime2DecodedAuthor.toLowerCase().indexOf(author) == 0, true, true, true, args.count);
+                mail.selectMessage(msg => msg.mime2DecodedAuthor.toLowerCase().indexOf(author) == 0, true, true, true, count);
             },
             { count: true });
 
@@ -595,22 +593,22 @@ const Mail = Module("mail", {
         // SCROLLING
         mappings.add(myModes, ["<Down>"],
             "Scroll message down",
-            function (args) { buffer.scrollLines(Math.max(args.count, 1)); },
+            function ({ count }) { buffer.scrollLines(Math.max(count, 1)); },
             { count: true });
 
         mappings.add(myModes, ["<Up>"],
             "Scroll message up",
-            function (args) { buffer.scrollLines(-Math.max(args.count, 1)); },
+            function ({ count }) { buffer.scrollLines(-Math.max(count, 1)); },
             { count: true });
 
         mappings.add([modes.MESSAGE], ["<Left>"],
             "Select previous message",
-            function (args) { mail.selectMessage(function (msg) true, false, false, true, args.count); },
+            function ({ count }) { mail.selectMessage(msg => true, false, false, true, count); },
             { count: true });
 
         mappings.add([modes.MESSAGE], ["<Right>"],
             "Select next message",
-            function (args) { mail.selectMessage(function (msg) true, false, false, false, args.count); },
+            function ({ count }) { mail.selectMessage(msg => true, false, false, false, count); },
             { count: true });
 
         // UNDO/REDO
@@ -659,29 +657,29 @@ const Mail = Module("mail", {
 
         mappings.add(myModes, ["]s"],
             "Select next starred message",
-            function (args) { mail.selectMessage(function (msg) msg.isFlagged, true, true, false, args.count); },
+            function ({ count }) { mail.selectMessage(msg => msg.isFlagged, true, true, false, count); },
             { count: true });
 
         mappings.add(myModes, ["[s"],
             "Select previous starred message",
-            function (args) { mail.selectMessage(function (msg) msg.isFlagged, true, true, true, args.count); },
+            function ({ count }) { mail.selectMessage(msg => msg.isFlagged, true, true, true, count); },
             { count: true });
 
         mappings.add(myModes, ["]a"],
             "Select next message with an attachment",
-            function (args) { mail.selectMessage(function (msg) gDBView.db.HasAttachments(msg.messageKey), true, true, false, args.count); },
+            function ({ count }) { mail.selectMessage(msg => gDBView.db.HasAttachments(msg.messageKey), true, true, false, count); },
             { count: true });
 
         mappings.add(myModes, ["[a"],
             "Select previous message with an attachment",
-            function (args) { mail.selectMessage(function (msg) gDBView.db.HasAttachments(msg.messageKey), true, true, true, args.count); },
+            function ({ count }) { mail.selectMessage(msg => gDBView.db.HasAttachments(msg.messageKey), true, true, true, count); },
             { count: true });
 
         // FOLDER SWITCHING
         mappings.add(myModes, ["gi"],
             "Go to inbox",
-            function (args) {
-                let folder = mail.getFolders("Inbox", false, true)[(args.count > 0) ? (args.count - 1) : 0];
+            function ({ count }) {
+                let folder = mail.getFolders("Inbox", false, true)[(count > 0) ? (count - 1) : 0];
                 if (folder)
                     SelectFolder(folder.URI);
                 else
@@ -691,8 +689,8 @@ const Mail = Module("mail", {
 
         mappings.add(myModes, ["<C-n>"],
             "Select next folder",
-            function (args) {
-                let newPos = mail._getCurrentFolderIndex() + Math.max(1, args.count);
+            function ({ count }) {
+                let newPos = mail._getCurrentFolderIndex() + Math.max(1, count);
                 if (newPos >= gFolderTreeView.rowCount) {
                     newPos = newPos % gFolderTreeView.rowCount;
                     commandline.echo(_("finder.atBottom"), commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES);
@@ -703,15 +701,15 @@ const Mail = Module("mail", {
 
         mappings.add(myModes, ["<C-N>"],
             "Go to next mailbox with unread messages",
-            function (args) {
-                mail._selectUnreadFolder(false, args.count);
+            function ({ count }) {
+                mail._selectUnreadFolder(false, count);
             },
             { count: true });
 
         mappings.add(myModes, ["<C-p>"],
             "Select previous folder",
-            function (args) {
-                let newPos = mail._getCurrentFolderIndex() - Math.max(1, args.count);
+            function ({ count }) {
+                let newPos = mail._getCurrentFolderIndex() - Math.max(1, count);
                 if (newPos < 0) {
                     newPos = (newPos % gFolderTreeView.rowCount) + gFolderTreeView.rowCount;
                     commandline.echo(_("finder.atTop"), commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES);
@@ -722,8 +720,8 @@ const Mail = Module("mail", {
 
         mappings.add(myModes, ["<C-P>"],
             "Go to previous mailbox with unread messages",
-            function (args) {
-                mail._selectUnreadFolder(true, args.count);
+            function ({ count }) {
+                mail._selectUnreadFolder(true, count);
             },
             { count: true });
 
@@ -771,19 +769,19 @@ const Mail = Module("mail", {
         // tagging messages
         mappings.add(myModes, ["l"],
             "Label message",
-            function (arg) {
+            function ({ arg }) {
                 if (!GetSelectedMessages())
                     return void dactyl.beep();
 
                 switch (arg) {
-                    case "r": MsgMarkMsgAsRead(); break;
-                    case "s": MsgMarkAsFlagged(); break;
-                    case "i": ToggleMessageTagKey(1); break; // Important
-                    case "w": ToggleMessageTagKey(2); break; // Work
-                    case "p": ToggleMessageTagKey(3); break; // Personal
-                    case "t": ToggleMessageTagKey(4); break; // TODO
-                    case "l": ToggleMessageTagKey(5); break; // Later
-                    default:  dactyl.beep();
+                case "r": MsgMarkMsgAsRead(); break;
+                case "s": MsgMarkAsFlagged(); break;
+                case "i": ToggleMessageTagKey(1); break; // Important
+                case "w": ToggleMessageTagKey(2); break; // Work
+                case "p": ToggleMessageTagKey(3); break; // Personal
+                case "t": ToggleMessageTagKey(4); break; // TODO
+                case "l": ToggleMessageTagKey(5); break; // Later
+                default:  dactyl.beep();
                 }
             },
             {
@@ -861,8 +859,8 @@ const Mail = Module("mail", {
     },
     services: function initServices(dactyl, modules, window) {
         services.add("smtp", "@mozilla.org/messengercompose/smtp;1", Ci.nsISmtpService);
+        services.add("compose", "@mozilla.org/messengercompose;1", "nsIMsgComposeService");
     },
-
     modes: function initModes(dactyl, modules, window) {
         modes.addMode("MESSAGE", {
             char: "m",
@@ -887,10 +885,10 @@ const Mail = Module("mail", {
             {
                 setter: function (value) {
                     switch (value) {
-                        case "classic":  ChangeMailLayout(0); break;
-                        case "wide":     ChangeMailLayout(1); break;
-                        case "vertical": ChangeMailLayout(2); break;
-                        // case "inherit" just does nothing
+                    case "classic":  ChangeMailLayout(0); break;
+                    case "wide":     ChangeMailLayout(1); break;
+                    case "vertical": ChangeMailLayout(2); break;
+                    // case "inherit" just does nothing
                     }
 
                     return value;
@@ -909,7 +907,7 @@ const Mail = Module("mail", {
             {
                 getter: function () services.smtp.defaultServer.key,
                 setter: function (value) {
-                    let server = mail.smtpServers.filter(function (s) s.key == value)[0];
+                    let server = mail.smtpServers.filter(s => s.key == value)[0];
                     services.smtp.defaultServer = server;
                     return value;
                 },
@@ -932,4 +930,4 @@ const Mail = Module("mail", {
     }
 });
 
-// vim: set fdm=marker sw=4 ts=4 et:
+// vim: set fdm=marker sw=4 sts=4 ts=8 et: