Bug 244455: Help prevent forgetting inclusion of attachments. ui-r=clarkbw, r=mkmelin,standard8
authorChinmay Patel <chinmay_patel@ymail.com>
Sat, 09 May 2009 16:29:17 +0300
changeset 2595 d6977a2fb36c124c72eadefd7369ec79bd43c20a
parent 2594 8cd0ec2d6de2217a69a19ff2da5569a0c37a33b3
child 2596 505c7833a920eab941c39be1addd18e598d11dcf
push idunknown
push userunknown
push dateunknown
reviewersclarkbw, mkmelin, standard8
bugs244455
Bug 244455: Help prevent forgetting inclusion of attachments. ui-r=clarkbw, r=mkmelin,standard8
mail/app/profile/all-thunderbird.js
mail/components/compose/content/MsgComposeCommands.js
mail/components/preferences/attachmentReminder.js
mail/components/preferences/attachmentReminder.xul
mail/components/preferences/compose.js
mail/components/preferences/compose.xul
mail/components/preferences/jar.mn
mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
mail/locales/en-US/chrome/messenger/preferences/attachmentReminder.dtd
mail/locales/en-US/chrome/messenger/preferences/compose.dtd
mail/locales/en-US/chrome/messenger/preferences/preferences.properties
mail/locales/jar.mn
--- a/mail/app/profile/all-thunderbird.js
+++ b/mail/app/profile/all-thunderbird.js
@@ -450,8 +450,13 @@ pref("mail.spotlight.logging.dump", fals
 #endif
 
 // Whether to use a panel that looks like an OS X sheet for customization
 #ifdef XP_MACOSX
 pref("toolbar.customization.usesheet", true);
 #else
 pref("toolbar.customization.usesheet", false);
 #endif
+
+// Check for missing attachments?
+pref("mail.compose.attachment_reminder", true);
+// Words that should trigger a missing attachments warning.
+pref("mail.compose.attachment_reminder_keywords", "chrome://messenger/locale/messengercompose/composeMsgs.properties");
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -1673,16 +1673,64 @@ function GenericSendMessage( msgType )
               var subjectInputElem = GetMsgSubjectElement();
               subjectInputElem.value = result.value;
             }
             else
               return;
           }
         }
 
+        // Attachment Reminder stuff...
+        var bucket = document.getElementById("attachmentBucket");
+        var warn = getPref("mail.compose.attachment_reminder");
+        if (warn && !bucket.itemCount)
+        {
+          var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+                                .getService(Components.interfaces.nsIPrefBranch);
+          var keywordsInCsv = prefs.getComplexValue("mail.compose.attachment_reminder_keywords",
+                                                    Components.interfaces.nsIPrefLocalizedString).data;
+          // And empty string pref is still going to get split to an array of
+          // size 1. Avoid that...
+          var keywordsArray = (keywordsInCsv) ? keywordsInCsv.split(",") : [];
+
+          var mailBody = document.getElementById("content-frame")
+                                 .contentDocument.getElementsByTagName("body")[0];
+          var mailBodyNode = mailBody.cloneNode(true);
+
+          // Don't check quoted text from reply.
+          var blockquotes = mailBodyNode.getElementsByTagName("blockquote");
+          for (let i = 0; i < blockquotes.length; i++)
+          {
+            blockquotes[i].parentNode.removeChild(blockquotes[i]);
+          }
+          var mailData = mailBodyNode.innerHTML;
+          var keywordFound;
+          for (let i = 0; i < keywordsArray.length && !keywordFound; i++)
+          {
+            var re = new RegExp(keywordsArray[i], "i");
+            keywordFound = re.exec(mailData);
+          }
+
+          if (keywordFound)
+          {
+            var bundle = document.getElementById("bundle_composeMsgs");
+            var flags = gPromptService.BUTTON_POS_0 * gPromptService.BUTTON_TITLE_IS_STRING +
+                        gPromptService.BUTTON_POS_1 * gPromptService.BUTTON_TITLE_IS_STRING;
+            var hadForgotten = gPromptService.confirmEx(null,
+                                 bundle.getString("attachmentReminderTitle"),
+                                 bundle.getString("attachmentReminderMsg"),
+                                 flags,
+                                 bundle.getString("attachmentReminderFalseAlarm"),
+                                 bundle.getString("attachmentReminderYesIForgot"),
+                                 null, null, {value:0});
+            if (hadForgotten)
+              return;
+          }
+        } // End of Attachment Reminder.
+
         // check if the user tries to send a message to a newsgroup through a mail account
         var currentAccountKey = getCurrentAccountKey();
         var account = gAccountManager.getAccount(currentAccountKey);
         if (!account)
         {
           throw "UNEXPECTED: currentAccountKey '" + currentAccountKey +
               "' has no matching account!";
         }
new file mode 100644
--- /dev/null
+++ b/mail/components/preferences/attachmentReminder.js
@@ -0,0 +1,122 @@
+# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Chinmay Deepakbhai Patel <chinu.ptl@gmail.com>.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Magnus Melin <mkmelin+mozilla@iki.fi>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var gAttachmentReminderOptionsDialog = {
+  prefs: null,
+  promptService: null,
+  keywordListBox: null,
+  bundle: null,
+
+  init: function()
+  {
+    this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
+                           .getService(Components.interfaces.nsIPrefBranch);
+    this.promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+                                   .getService(Components.interfaces.nsIPromptService);
+    this.keywordListBox = document.getElementById("keywordList");
+    this.bundle = document.getElementById("bundlePreferences");
+    this.buildKeywordList();
+  },
+
+  buildKeywordList: function()
+  {
+    var keywordsInCsv = this.prefs.getComplexValue("mail.compose.attachment_reminder_keywords",
+                                                   Components.interfaces.nsIPrefLocalizedString);
+    if (!keywordsInCsv)
+      return;
+    var keywordsInCsv = keywordsInCsv.data;
+    var keywordsInArr = keywordsInCsv.split(",");
+    for (var i = 0; i < keywordsInArr.length; i++)
+    {
+      if (keywordsInArr[i])
+        this.keywordListBox.appendItem(keywordsInArr[i], keywordsInArr[i]);
+    }
+    if (keywordsInArr.length)
+      this.keywordListBox.selectedIndex = 0;
+  },
+
+  addKeyword: function()
+  {
+    var input = {value: ""}; // Default to empty.
+    var ok = this.promptService.prompt(window,
+                                       this.bundle.getString("attachmentReminderAddDialogTitle"),
+                                       this.bundle.getString("attachmentReminderAddText"),
+                                       input, null, {value:0});
+    if (ok && input.value)
+      this.keywordListBox.appendItem(input.value, input.value);
+  },
+
+  editKeyword: function()
+  {
+    if (this.keywordListBox.selectedIndex < 0)
+      return;
+    var keywordToEdit = this.keywordListBox.getItemAtIndex(this.keywordListBox.selectedIndex);
+    var input = {value: keywordToEdit.getAttribute("value")};
+    var ok = this.promptService.prompt(window,
+                                       this.bundle.getString("attachmentReminderEditDialogTitle"),
+                                       this.bundle.getString("attachmentReminderEditText"),
+                                       input, null, {value:0});
+    if (ok && input.value) {
+      this.keywordListBox.removeItemAt(this.keywordListBox.selectedIndex);
+      this.keywordListBox.appendItem(input.value, input.value);
+    }
+  },
+
+  removeKeyword: function()
+  {
+    if (this.keywordListBox.selectedIndex < 0)
+      return;
+    this.keywordListBox.removeItemAt(this.keywordListBox.selectedIndex);
+  },
+
+  saveKeywords: function()
+  {
+    var keywordList = "";
+    for (var i = 0; i < this.keywordListBox.getRowCount(); i++) {
+      keywordList += this.keywordListBox.getItemAtIndex(i).getAttribute("value");
+      if (i != this.keywordListBox.getRowCount() - 1)
+        keywordList += ",";
+    }
+
+    var str = Components.classes["@mozilla.org/supports-string;1"]
+                        .createInstance(Components.interfaces.nsISupportsString);
+    str.data = keywordList;
+    this.prefs.setComplexValue("mail.compose.attachment_reminder_keywords",
+                               Components.interfaces.nsISupportsString, str);
+  }
+};
new file mode 100644
--- /dev/null
+++ b/mail/components/preferences/attachmentReminder.xul
@@ -0,0 +1,77 @@
+<?xml version="1.0"?>
+# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is mozilla.org code.
+#
+# The Initial Developer of the Original Code is
+# Chinmay Deepakbhai Patel <chinu.ptl@gmail.com>.
+# Portions created by the Initial Developer are Copyright (C) 2009
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#   Magnus Melin <mkmelin+mozilla@iki.fi>
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+<?xml-stylesheet href="chrome://global/skin/"?>
+<!DOCTYPE prefwindow [
+<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
+%brandDTD;
+<!ENTITY % sendOptionsDTD SYSTEM "chrome://messenger/locale/preferences/attachmentReminder.dtd">
+%sendOptionsDTD;
+]>
+
+<prefwindow id="attachmentReminderOptionsDialog" type="child"
+            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+            dlgbuttons="accept,cancel"
+            title="&attachmentReminderDialog.title;"
+            ondialogaccept="gAttachmentReminderOptionsDialog.saveKeywords();"
+            style="width:38em;">
+
+  <prefpane id="attachmentReminderOptionsDialogPane"
+            onpaneload="gAttachmentReminderOptionsDialog.init();">
+
+    <script type="application/javascript" src="chrome://messenger/content/preferences/attachmentReminder.js"/>
+    <stringbundle id="bundlePreferences" src="chrome://messenger/locale/preferences/preferences.properties"/>
+
+    <groupbox>
+      <label control="keywordList">&attachKeywordText.label;</label>
+      <hbox>
+        <listbox id="keywordList" flex="1" rows="5"
+                 ondblclick="gAttachmentReminderOptionsDialog.editKeyword();"/>
+        <vbox>
+          <button label="&addKeywordButton.label;" accesskey="&addKeywordButton.accesskey;"
+                  oncommand="gAttachmentReminderOptionsDialog.addKeyword();"/>
+          <button label="&editKeywordButton.label;" accesskey="&editKeywordButton.accesskey;"
+                  oncommand="gAttachmentReminderOptionsDialog.editKeyword();"/>
+          <button label="&removeKeywordButton.label;" accesskey="&removeKeywordButton.accesskey;"
+                  oncommand="gAttachmentReminderOptionsDialog.removeKeyword();"/>
+        </vbox>
+      </hbox>
+    </groupbox>
+  </prefpane>
+</prefwindow>
--- a/mail/components/preferences/compose.js
+++ b/mail/components/preferences/compose.js
@@ -74,16 +74,21 @@ var gComposePane = {
     }
   },
 
   sendOptionsDialog: function()
   {
     document.documentElement.openSubDialog("chrome://messenger/content/preferences/sendoptions.xul","", null);
   },
 
+  attachmentReminderOptionsDialog: function()
+  {
+    document.documentElement.openSubDialog("chrome://messenger/content/preferences/attachmentReminder.xul", "", null);
+  },
+
   htmlComposeDialog: function()
   {
     document.documentElement.openSubDialog("chrome://messenger/content/preferences/htmlcompose.xul","", null);
   },
 
   enableElement: function(aElement, aEnable)
   {
     var pref = document.getElementById(aElement.getAttribute("preference"));
--- a/mail/components/preferences/compose.xul
+++ b/mail/components/preferences/compose.xul
@@ -74,16 +74,19 @@
                   name="pref.ldap.disable_button.edit_directories" type="bool"/>
       <preference id="mail.collect_email_address_outgoing" name="mail.collect_email_address_outgoing" type="bool"/>
       <preference id="mail.collect_addressbook" name="mail.collect_addressbook" type="string"/>
       <preference id="spellchecker.dictionary"  name="spellchecker.dictionary"   type="unichar"/>
       <preference id="msgcompose.font_face"      name="msgcompose.font_face" type="string"/>
       <preference id="msgcompose.font_size"      name="msgcompose.font_size" type="string"/>
       <preference id="msgcompose.text_color"     name="msgcompose.text_color" type="string"/>
       <preference id="msgcompose.background_color" name="msgcompose.background_color" type="string"/>      
+      <preference id="mail.compose.attachment_reminder"
+                  name="mail.compose.attachment_reminder"
+                  type="bool"/>
     </preferences>
 
     <tabbox id="composePrefs" flex="1" onselect="gComposePane.tabSelectionChanged();">
       <tabs>
         <tab label="&itemGeneral.label;"/>
         <tab label="&itemAutoComplete.label;"/>
         <tab label="&itemSpellCheck.label;"/>
       </tabs>
@@ -110,16 +113,28 @@
                        preference="mail.compose.autosaveinterval"
                        aria-labelledby="autoSave autoSaveInterval autoSaveEnd"/>
               <label id="autoSaveEnd" value="&autoSaveEnd.label;"/>
             </hbox>
 
             <checkbox id="mailWarnOnSendAccelKey" label="&warnOnSendAccelKey.label;"
                       preference="mail.warn_on_send_accel_key"
                       accesskey="&warnOnSendAccelKey.accesskey;"/>
+
+            <hbox align="center">
+              <checkbox id="attachment_reminder_label"
+                        label="&attachmentReminder.label;"
+                        accesskey="&attachmentReminder.accesskey;"
+                        preference="mail.compose.attachment_reminder"
+                        flex="1"/>
+              <button label="&attachmentReminderOptions.label;"
+                      accesskey="&attachmentReminderOptions.accesskey;"
+                      oncommand="gComposePane.attachmentReminderOptionsDialog();"/>
+            </hbox>
+
           </groupbox>
 
           <groupbox>
             <caption label="&htmlComposeHeader.label;"/>
             <hbox align="center">
               <label control="FontSelect" value="&font.label;" accesskey="&font.accesskey;"/>
               <menulist id="FontSelect" preference="msgcompose.font_face">
                 <menupopup>
--- a/mail/components/preferences/jar.mn
+++ b/mail/components/preferences/jar.mn
@@ -14,16 +14,18 @@ messenger.jar:
 *   content/messenger/preferences/junkLog.js
 *   content/messenger/preferences/advanced.js
 *   content/messenger/preferences/advanced.xul
 *   content/messenger/preferences/receipts.xul
 *   content/messenger/preferences/connection.js
 *   content/messenger/preferences/connection.xul
 *   content/messenger/preferences/downloads.js
 *   content/messenger/preferences/downloads.xul
+*   content/messenger/preferences/attachmentReminder.js
+*   content/messenger/preferences/attachmentReminder.xul
 *   content/messenger/preferences/downloadactions.js
 *   content/messenger/preferences/downloadactions.xul
 *   content/messenger/preferences/actionsshared.js
 *   content/messenger/preferences/changeaction.js
 *   content/messenger/preferences/changeaction.xul
 *   content/messenger/preferences/fonts.js
 *   content/messenger/preferences/fonts.xul
 *   content/messenger/preferences/notifications.xul
--- a/mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
+++ b/mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
@@ -322,8 +322,18 @@ mailnews.reply_header_ondate=On %s
 
 ## reply header in composeMsg
 ## user specified 
 mailnews.reply_header_originalmessage=-------- Original Message --------
 
 ## Strings used by the rename attachment dialog
 renameAttachmentTitle=Rename Attachment
 renameAttachmentMessage=New attachment name:
+
+## Attachment Reminder
+## LOCALIZATION NOTE (mail.compose.attachment_reminder_keywords): comma separated
+##   words that that should trigger an attachment reminder.
+mail.compose.attachment_reminder_keywords=attachment,attached,.doc,.pdf,resume,cover letter
+attachmentReminderTitle=Attachment Reminder
+attachmentReminderMsg=Did you forget to add an attachment?
+attachmentReminderYesIForgot=Oh, I did!
+attachmentReminderFalseAlarm=No, Send Now
+
new file mode 100644
--- /dev/null
+++ b/mail/locales/en-US/chrome/messenger/preferences/attachmentReminder.dtd
@@ -0,0 +1,8 @@
+<!ENTITY attachmentReminderDialog.title   "Attachment Reminder Keywords">
+<!ENTITY attachKeywordText.label          "&brandShortName; will warn you about missing attachments if the you're about to send an e-mail containing one of these keywords.">
+<!ENTITY addKeywordButton.label           "Add">
+<!ENTITY addKeywordButton.accesskey       "A">
+<!ENTITY editKeywordButton.label          "Edit">
+<!ENTITY editKeywordButton.accesskey      "E">
+<!ENTITY removeKeywordButton.label        "Delete">
+<!ENTITY removeKeywordButton.accesskey    "D">
--- a/mail/locales/en-US/chrome/messenger/preferences/compose.dtd
+++ b/mail/locales/en-US/chrome/messenger/preferences/compose.dtd
@@ -45,8 +45,13 @@
 <!ENTITY directories.accesskey                 "D">
 <!ENTITY directoriesNone.label                 "None">
 <!ENTITY editDirectories.label                 "Edit Directories…">
 <!ENTITY editDirectories.accesskey             "E">
 
 <!ENTITY sendOptionsDescription.label          "Configure text format behavior">
 <!ENTITY sendOptions.label                     "Send Options…">
 <!ENTITY sendOptions.accesskey                 "S">
+
+<!ENTITY attachmentReminder.label              "Check for missing attachments">
+<!ENTITY attachmentReminder.accesskey          "m">
+<!ENTITY attachmentReminderOptions.label       "Keywords…">
+<!ENTITY attachmentReminderOptions.accesskey   "K">
--- a/mail/locales/en-US/chrome/messenger/preferences/preferences.properties
+++ b/mail/locales/en-US/chrome/messenger/preferences/preferences.properties
@@ -37,8 +37,14 @@ fpTitleChooseApp=Select Helper Applicati
 fpTitleChooseDL=Select Download Folder
 
 #### Sound Notifications
 soundFilePickerTitle=Choose Sound
 
 #### Shell Service
 alreadyDefaultClientTitle=Default Client
 alreadyDefault=%S is already set as your default mail client.
+
+#### Attachment Reminder
+attachmentReminderAddDialogTitle=Add Keyword
+attachmentReminderAddText=Keyword:
+attachmentReminderEditDialogTitle=Edit Keyword
+attachmentReminderEditText=Keyword:
--- a/mail/locales/jar.mn
+++ b/mail/locales/jar.mn
@@ -114,16 +114,17 @@
   locale/@AB_CD@/messenger/preferences/preferences.dtd                  (%chrome/messenger/preferences/preferences.dtd)
   locale/@AB_CD@/messenger/preferences/general.dtd                      (%chrome/messenger/preferences/general.dtd)
   locale/@AB_CD@/messenger/preferences/display.dtd                      (%chrome/messenger/preferences/display.dtd)
   locale/@AB_CD@/messenger/preferences/compose.dtd                      (%chrome/messenger/preferences/compose.dtd)
   locale/@AB_CD@/messenger/preferences/sendoptions.dtd                  (%chrome/messenger/preferences/sendoptions.dtd)
   locale/@AB_CD@/messenger/preferences/security.dtd                     (%chrome/messenger/preferences/security.dtd)
   locale/@AB_CD@/messenger/preferences/junkLog.dtd                      (%chrome/messenger/preferences/junkLog.dtd)
   locale/@AB_CD@/messenger/preferences/advanced.dtd                     (%chrome/messenger/preferences/advanced.dtd)
+  locale/@AB_CD@/messenger/preferences/attachmentReminder.dtd           (%chrome/messenger/preferences/attachmentReminder.dtd)
   locale/@AB_CD@/messenger/preferences/receipts.dtd                     (%chrome/messenger/preferences/receipts.dtd)
   locale/@AB_CD@/messenger/preferences/connection.dtd                   (%chrome/messenger/preferences/connection.dtd)
   locale/@AB_CD@/messenger/preferences/downloads.dtd                    (%chrome/messenger/preferences/downloads.dtd)
   locale/@AB_CD@/messenger/preferences/downloadactions.dtd              (%chrome/messenger/preferences/downloadactions.dtd)
   locale/@AB_CD@/messenger/preferences/changeaction.dtd                 (%chrome/messenger/preferences/changeaction.dtd)
   locale/@AB_CD@/messenger/preferences/fonts.dtd                        (%chrome/messenger/preferences/fonts.dtd)
   locale/@AB_CD@/messenger/preferences/offline.dtd                      (%chrome/messenger/preferences/offline.dtd)
   locale/@AB_CD@/messenger/preferences/notifications.dtd                (%chrome/messenger/preferences/notifications.dtd)