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

source: content/vI_smartIdentity.js @ ca4823

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

continue to change pref-usage into module (nearly done)

  • Property mode set to 100644
File size: 10.7 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    _smartIdentityCollection : null,
39       
40    // After Loading the MessageComposeDialog, check if smartIdentity is needed
41    init : function() {
42        var msgHdr;
43        var msgComposeTypeReference = Components.interfaces.nsIMsgCompType;
44        var newsgroup = gMsgCompose.compFields.newsgroups;
45        var autocreate = false;
46        Log.debug("msgComposeTypeReference = " + gMsgCompose.type + "\n");
47        switch (gMsgCompose.type) {
48            case msgComposeTypeReference.Reply:
49            case msgComposeTypeReference.ReplyAll:
50            case msgComposeTypeReference.ReplyToGroup: // reply to a newsgroup, would possibly be stopped later
51            case msgComposeTypeReference.ReplyToSender:
52            case msgComposeTypeReference.ReplyToSenderAndGroup: // reply to a newsgroup, would possibly be stopped later
53            case msgComposeTypeReference.ReplyWithTemplate:
54            case msgComposeTypeReference.ReplyToList:
55                Log.debug("Reply\n");
56                msgHdr = smartIdentity.messenger.
57                    messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI);
58                smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients()); 
59                smartIdentity._smartIdentityCollection.Reply();
60                autocreate = false; break;
61            case msgComposeTypeReference.Draft:
62            case msgComposeTypeReference.Template:
63                Log.debug("Draft\n");
64                msgHdr = smartIdentity.messenger.
65                    messageServiceFromURI(gMsgCompose.compFields.draftId).messageURIToMsgHdr(gMsgCompose.compFields.draftId);
66                smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients()); 
67                smartIdentity._smartIdentityCollection.Draft();
68                autocreate = false; break;
69            case msgComposeTypeReference.ForwardAsAttachment:
70            case msgComposeTypeReference.ForwardInline:
71            case msgComposeTypeReference.New:
72            case msgComposeTypeReference.NewsPost:
73            case msgComposeTypeReference.MailToUrl:
74                Log.debug("New Mail\n");
75                smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(null, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients());   
76                // to enable composing new email with new identity: identity is hidden in subject line
77                // used for instance from conversation addon
78                var subject = gMsgCompose.compFields.subject.split(/\n/);
79                if (subject.length > 1 && subject[1] == "virtualIdentityExtension") {
80                    Log.debug("NewMail() found stored identity preset: " + subject[2] + "\n");
81                    smartIdentity._smartIdentityCollection.__parseHeadersWithArray(subject[2], smartIdentity._smartIdentityCollection._allIdentities);
82                    gMsgCompose.compFields.subject = subject[0];
83                    document.getElementById("msgSubject").value = subject[0];
84                }
85                else smartIdentity._smartIdentityCollection.NewMail();
86                autocreate = true; break;
87        }
88        if (smartIdentity._smartIdentityCollection._allIdentities.number > 0) smartIdentity.__smartIdentitySelection(autocreate);
89    },
90   
91    _getRecipients : function() {
92        var recipients = [];
93        for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
94            var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
95            if (recipientType == "addr_reply" || recipientType == "addr_followup" || 
96                vI.storage.__isDoBcc(row) || awGetInputElement(row).value.match(/^\s*$/) ) continue;
97            recipients.push( { recipient: awGetInputElement(row).value, recipientType : recipientType } );
98        }
99        return recipients;
100    },
101   
102    __smartIdentitySelection : function(autocreate) {
103        Log.debug("__smartIdentitySelection autocreate=" + autocreate + "\n");
104       
105        if (vI.vIprefs.get("idSelection_preferExisting")) {
106            var existingIDIndex = smartIdentity._smartIdentityCollection._foundExistingIdentity();
107            if (existingIDIndex) {
108                Log.debug("found existing Identity, use without interaction.\n");
109                // add all Indentities to Clone Menu before selecting and leaving the function
110                document.getElementById("virtualIdentityExtension_msgIdentityClone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities);
111                smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, existingIDIndex.key);
112                return;
113            }
114        }
115       
116        document.getElementById("virtualIdentityExtension_msgIdentityClone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities);
117        Log.debug("__smartIdentitySelection smartIdentity._smartIdentityCollection._allIdentities.number=" +
118                smartIdentity._smartIdentityCollection._allIdentities.number +
119                " vI.vIprefs.get('idSelection_ask_always')=" +
120                vI.vIprefs.get("idSelection_ask_always") +
121                " vI.vIprefs.get('idSelection_ask')=" +
122                vI.vIprefs.get("idSelection_ask") + "\n");
123        if (!autocreate && vI.vIprefs.get("idSelection_ask") && 
124            ((smartIdentity._smartIdentityCollection._allIdentities.number == 1 && vI.vIprefs.get("idSelection_ask_always"))
125                || smartIdentity._smartIdentityCollection._allIdentities.number > 1)) {
126            for (var index = 0; index < smartIdentity._smartIdentityCollection._allIdentities.number; index++) {
127                Log.debug("smartIdentityReplyDialog index=" + index + ": '" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].combinedName + "' "
128                    + "(" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].id.value + "," + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].smtp.value + ")\n");
129            }
130            window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0,
131                    "chrome, dialog, modal, alwaysRaised, resizable=yes",
132                     smartIdentity._smartIdentityCollection._allIdentities,
133                    /* callback: */ smartIdentity.changeIdentityToSmartIdentity).focus();
134        }
135        else if (autocreate || vI.vIprefs.get("idSelection_autocreate")) {
136            smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, 0);
137        }   
138    },
139   
140    changeIdentityToSmartIdentity : function(allIdentities, selectedValue) {
141        Log.debug("changeIdentityToSmartIdentity selectedValue=" + selectedValue + " from " + allIdentities.number + "\n");
142        Log.debug("changeIdentityToSmartIdentity selectedValue=" + selectedValue + ": '" + allIdentities.identityDataCollection[selectedValue].combinedName + "' "
143            + "(" + allIdentities.identityDataCollection[selectedValue].id.value + "," + allIdentities.identityDataCollection[selectedValue].smtp.value + ")\n");
144        document.getElementById("virtualIdentityExtension_msgIdentityClone").selectedMenuItem = allIdentities.menuItems[selectedValue];
145        if (document.getElementById("virtualIdentityExtension_msgIdentityClone").vid) {
146            var label=vI.main.elements.strings.getString("vident.smartIdentity.vIUsage");
147            if (allIdentities.number > 1) label += " "
148                + vI.main.elements.strings.getString("vident.smartIdentity.moreThanOne");
149            vI.SmartReplyNotification.info(label + ".");
150        }
151        smartIdentity.__removeSmartIdentityFromRecipients(allIdentities, selectedValue);
152    },
153   
154    __removeSmartIdentityFromRecipients : function(allIdentities, index) {
155        if (!vI.vIprefs.get("idSelection_removeSmartIdentityFromRecipients")) return;
156       
157        // check if selected email is defined as doBcc address. If so, it should not be removed.
158        var skip_bcc = false;
159        if (getCurrentIdentity().doBcc) {
160            var bcc_addresses = new vI.identityCollection();
161            smartIdentity.__parseHeadersWithArray(getCurrentIdentity().doBccList, bcc_addresses);
162           
163            for (var i = 0; i < bcc_addresses.number; i++) {
164                if (allIdentities.identityDataCollection[index].email == bcc_addresses.identityDataCollection[i].email) {
165                    skip_bcc = true; break;
166                }
167            }
168        }
169       
170        // check if there is more than one recipient for this mail. If not, preserve the only one existing.
171        var recipientCount = 0;
172        for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
173            var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
174            if (recipientType == "addr_to" || recipientType == "addr_cc") recipientCount++;
175        }
176        if (recipientCount < 2) return;
177       
178       
179        for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
180            var popup = awGetPopupElement(row);
181            var input = awGetInputElement(row);
182            var recipientType = popup.selectedItem.getAttribute("value");
183            // if the entry is not a recipient, just continue
184            if (recipientType == "addr_reply" || recipientType == "addr_followup") continue;
185            // check if the entry is used as a BCC selected in account settings
186            if (recipientType == "addr_bcc" && skip_bcc) continue;
187            // check if entry is matching senders address, if so, remove it
188            if (input.value == allIdentities.identityDataCollection[index].email ||
189                input.value == allIdentities.identityDataCollection[index].combinedName) {
190                    awSetInputAndPopupValue(input, "", popup, "addr_to", -1);
191                    awCleanupRows()
192                    vI.SmartReplyNotification.info(" " +    vI.main.elements.strings.getString("vident.smartIdentity.remRecipient"));
193                    break;
194            }
195        }
196    }
197}
198vI.smartIdentity = smartIdentity;
199}});
Note: See TracBrowser for help on using the repository browser.