This is just some static backup of the original site, don't expect every link to work!

source: content/vI_smartIdentity.js @ 449944

ng_0.9
Last change on this file since 449944 was 449944, checked in by rene <rene@…>, 10 years ago

bugfix: using storage with new mail

  • Property mode set to 100644
File size: 10.9 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24
25Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
26virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
27
28let Log = vI.setupLogging("virtualIdentity.smartIdentity");
29
30Components.utils.import("resource://v_identity/vI_identityData.js", virtualIdentityExtension);
31Components.utils.import("resource://v_identity/vI_smartIdentityCollection.js", virtualIdentityExtension);
32Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
33
34var smartIdentity = {
35    messenger : Components.classes["@mozilla.org/messenger;1"].createInstance()
36        .QueryInterface(Components.interfaces.nsIMessenger),
37   
38    stringBundle : Components.classes["@mozilla.org/intl/stringbundle;1"]
39        .getService(Components.interfaces.nsIStringBundleService)
40        .createBundle("chrome://v_identity/locale/v_identity.properties"),
41
42    _smartIdentityCollection : null,
43       
44    // After Loading the MessageComposeDialog, check if smartIdentity is needed
45    init : function(currentWindow) {
46        var msgHdr;
47        var msgComposeTypeReference = Components.interfaces.nsIMsgCompType;
48        var newsgroup = gMsgCompose.compFields.newsgroups;
49        var autocreate = false;
50        Log.debug("msgComposeTypeReference = " + gMsgCompose.type);
51        switch (gMsgCompose.type) {
52            case msgComposeTypeReference.Reply:
53            case msgComposeTypeReference.ReplyAll:
54            case msgComposeTypeReference.ReplyToGroup: // reply to a newsgroup, would possibly be stopped later
55            case msgComposeTypeReference.ReplyToSender:
56            case msgComposeTypeReference.ReplyToSenderAndGroup: // reply to a newsgroup, would possibly be stopped later
57            case msgComposeTypeReference.ReplyWithTemplate:
58            case msgComposeTypeReference.ReplyToList:
59                Log.debug("Reply");
60                msgHdr = smartIdentity.messenger.
61                    messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI);
62                smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow)); 
63                smartIdentity._smartIdentityCollection.Reply();
64                autocreate = false; break;
65            case msgComposeTypeReference.Draft:
66            case msgComposeTypeReference.Template:
67                Log.debug("Draft");
68                msgHdr = smartIdentity.messenger.
69                    messageServiceFromURI(gMsgCompose.compFields.draftId).messageURIToMsgHdr(gMsgCompose.compFields.draftId);
70                smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow)); 
71                smartIdentity._smartIdentityCollection.Draft();
72                autocreate = false; break;
73            case msgComposeTypeReference.ForwardAsAttachment:
74            case msgComposeTypeReference.ForwardInline:
75            case msgComposeTypeReference.New:
76            case msgComposeTypeReference.NewsPost:
77            case msgComposeTypeReference.MailToUrl:
78                Log.debug("New Mail");
79                smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(null, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow));   
80                // to enable composing new email with new identity: identity is hidden in subject line
81                // used for instance from conversation addon
82                var subject = gMsgCompose.compFields.subject.split(/\n/);
83                if (subject.length > 1 && subject[1] == "virtualIdentityExtension") {
84                    Log.debug("NewMail() found stored identity preset: " + subject[2]);
85                    smartIdentity._smartIdentityCollection.__parseHeadersWithArray(subject[2], smartIdentity._smartIdentityCollection._allIdentities);
86                    gMsgCompose.compFields.subject = subject[0];
87                    document.getElementById("msgSubject").value = subject[0];
88                }
89                else smartIdentity._smartIdentityCollection.NewMail();
90                autocreate = true; break;
91        }
92        if (smartIdentity._smartIdentityCollection._allIdentities.number > 0) smartIdentity.__smartIdentitySelection(autocreate);
93    },
94   
95    _getRecipients : function(currentWindow) {
96        var recipients = [];
97        for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
98            var recipientType = currentWindow.awGetPopupElement(row).selectedItem.getAttribute("value");
99            if (recipientType == "addr_reply" || recipientType == "addr_followup" || 
100                vI.storage.isDoBcc(row, currentWindow) || currentWindow.awGetInputElement(row).value.match(/^\s*$/) ) continue;
101            recipients.push( { recipient: currentWindow.awGetInputElement(row).value, recipientType : recipientType } );
102        }
103        return recipients;
104    },
105   
106    __smartIdentitySelection : function(autocreate) {
107        Log.debug("__smartIdentitySelection autocreate=" + autocreate);
108       
109        if (vI.vIprefs.get("idSelection_preferExisting")) {
110            var existingIDIndex = smartIdentity._smartIdentityCollection._foundExistingIdentity();
111            if (existingIDIndex) {
112                Log.debug("found existing Identity, use without interaction.");
113                // add all Indentities to Clone Menu before selecting and leaving the function
114                document.getElementById("virtualIdentityExtension_msgIdentityClone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities);
115                smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, existingIDIndex.key);
116                return;
117            }
118        }
119       
120        document.getElementById("virtualIdentityExtension_msgIdentityClone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities);
121        Log.debug("__smartIdentitySelection _allIdentities.number=" +
122                smartIdentity._smartIdentityCollection._allIdentities.number +
123                " _ask_always=" + vI.vIprefs.get("idSelection_ask_always") +
124                " _ask=" + vI.vIprefs.get("idSelection_ask"));
125        if (!autocreate && vI.vIprefs.get("idSelection_ask") && 
126            ((smartIdentity._smartIdentityCollection._allIdentities.number == 1 && vI.vIprefs.get("idSelection_ask_always"))
127                || smartIdentity._smartIdentityCollection._allIdentities.number > 1)) {
128            for (var index = 0; index < smartIdentity._smartIdentityCollection._allIdentities.number; index++) {
129                Log.debug("smartIdentityReplyDialog index=" + index + ": '" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].combinedName + "' "
130                    + "(" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].id.value + "," + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].smtp.value + ")");
131            }
132            window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0,
133                    "chrome, dialog, modal, alwaysRaised, resizable=yes",
134                     smartIdentity._smartIdentityCollection._allIdentities,
135                    /* callback: */ smartIdentity.changeIdentityToSmartIdentity).focus();
136        }
137        else if (autocreate || vI.vIprefs.get("idSelection_autocreate")) {
138            smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, 0);
139        }   
140    },
141   
142    changeIdentityToSmartIdentity : function(allIdentities, selectedValue) {
143        Log.debug("changeIdentityToSmartIdentity selectedValue=" + selectedValue + " from " + allIdentities.number);
144        Log.debug("changeIdentityToSmartIdentity selectedValue=" + selectedValue + ": '" + allIdentities.identityDataCollection[selectedValue].combinedName + "' "
145            + "(" + allIdentities.identityDataCollection[selectedValue].id.value + "," + allIdentities.identityDataCollection[selectedValue].smtp.value + ")");
146        document.getElementById("virtualIdentityExtension_msgIdentityClone").selectedMenuItem = allIdentities.menuItems[selectedValue];
147        if (document.getElementById("virtualIdentityExtension_msgIdentityClone").vid) {
148            var label=smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.vIUsage");
149            if (allIdentities.number > 1) label += " "
150                + smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.moreThanOne");
151            vI.SmartReplyNotification.info(label + ".");
152        }
153        smartIdentity.__removeSmartIdentityFromRecipients(allIdentities, selectedValue);
154    },
155   
156    __removeSmartIdentityFromRecipients : function(allIdentities, index) {
157        if (!vI.vIprefs.get("idSelection_removeSmartIdentityFromRecipients")) return;
158       
159        // check if selected email is defined as doBcc address. If so, it should not be removed.
160        var skip_bcc = false;
161        if (getCurrentIdentity().doBcc) {
162            var bcc_addresses = new vI.identityCollection();
163            smartIdentity.__parseHeadersWithArray(getCurrentIdentity().doBccList, bcc_addresses);
164           
165            for (var i = 0; i < bcc_addresses.number; i++) {
166                if (allIdentities.identityDataCollection[index].email == bcc_addresses.identityDataCollection[i].email) {
167                    skip_bcc = true; break;
168                }
169            }
170        }
171       
172        // check if there is more than one recipient for this mail. If not, preserve the only one existing.
173        var recipientCount = 0;
174        for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
175            var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
176            if (recipientType == "addr_to" || recipientType == "addr_cc") recipientCount++;
177        }
178        if (recipientCount < 2) return;
179       
180       
181        for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
182            var popup = awGetPopupElement(row);
183            var input = awGetInputElement(row);
184            var recipientType = popup.selectedItem.getAttribute("value");
185            // if the entry is not a recipient, just continue
186            if (recipientType == "addr_reply" || recipientType == "addr_followup") continue;
187            // check if the entry is used as a BCC selected in account settings
188            if (recipientType == "addr_bcc" && skip_bcc) continue;
189            // check if entry is matching senders address, if so, remove it
190            if (input.value == allIdentities.identityDataCollection[index].email ||
191                input.value == allIdentities.identityDataCollection[index].combinedName) {
192                    awSetInputAndPopupValue(input, "", popup, "addr_to", -1);
193                    awCleanupRows()
194                    vI.SmartReplyNotification.info(" " + smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.remRecipient"));
195                    break;
196            }
197        }
198    }
199}
200vI.smartIdentity = smartIdentity;
201}});
Note: See TracBrowser for help on using the repository browser.