Bug 646638 - vCards from webpages and the desktop cannot be opened / imported to Thunderbird r=squib
authorJonathan Protzenko <jonathan.protzenko@gmail.com>
Sat, 17 Sep 2011 21:21:43 +0200
changeset 9192 adb328ea98c92ce1af4fbf50cc8b31238407f98c
parent 9191 9c042ec0a30341f17973e4241f3e27c7ae2030cb
child 9193 31a247f6426c2ee4fc894d7ada338c71b9ee9f7d
push id230
push userbugzilla@standard8.plus.com
push dateTue, 08 Nov 2011 22:55:24 +0000
treeherdercomm-beta@63dad5648415 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssquib
bugs646638
Bug 646638 - vCards from webpages and the desktop cannot be opened / imported to Thunderbird r=squib
mail/components/nsMailDefaultHandler.js
--- a/mail/components/nsMailDefaultHandler.js
+++ b/mail/components/nsMailDefaultHandler.js
@@ -32,17 +32,20 @@
  * 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 ***** */
 
+Components.utils.import("resource://gre/modules/NetUtil.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource:///modules/mailServices.js");
 
 const nsISupports              = Components.interfaces.nsISupports;
 
 const nsICommandLine           = Components.interfaces.nsICommandLine;
 const nsICommandLineHandler    = Components.interfaces.nsICommandLineHandler;
 const nsICommandLineValidator  = Components.interfaces.nsICommandLineValidator;
 const nsIDOMWindow             = Components.interfaces.nsIDOMWindow;
 const nsIFactory               = Components.interfaces.nsIFactory;
@@ -402,16 +405,37 @@ var nsMailDefaultHandler = {
             message = bundle.formatStringFromName("fileEmptyMsg", [file.path], 1);
           }
 
           let promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                                         .getService(Components.interfaces.nsIPromptService);
           promptService.alert(null, title, message);
         }
       }
+      else if (/\.vcf$/i.test(uri)) {
+        // A VCard! Be smart and open the "add contact" dialog.
+        let file = cmdLine.resolveFile(uri);
+        if (file.exists() && file.fileSize > 0) {
+          NetUtil.asyncFetch(file, function(inputStream, status) {
+            if (!Components.isSuccessCode(status)) {
+              return;
+            }
+
+            let data = NetUtil.readInputStreamToString(
+              inputStream, inputStream.available());
+            let card = MailServices.ab.escapedVCardToAbCard(data);
+            Services.ww.openWindow(
+              null,
+              "chrome://messenger/content/addressbook/abNewCardDialog.xul",
+              "_blank",
+              "chrome,resizable=no,titlebar,modal,centerscreen",
+              card);
+          });
+        }
+      }
       else {
         // This must be a regular filename. Use it to create a new message with attachment.
         let msgComposeService = Components.classes["@mozilla.org/messengercompose;1"]
                                           .getService(Components.interfaces.nsIMsgComposeService);
         let msgParams = Components.classes["@mozilla.org/messengercompose/composeparams;1"]
                                   .createInstance(Components.interfaces.nsIMsgComposeParams);
         let composeFields = Components.classes["@mozilla.org/messengercompose/composefields;1"]
                                       .createInstance(Components.interfaces.nsIMsgCompFields);