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

source: chrome/content/v_identity/v_identity.js @ e0d779

multiEditng_0.6ng_0.8ng_0.9
Last change on this file since e0d779 was e0d779, checked in by rene <rene@…>, 13 years ago

don't show fcc-switch when using real identity, it won't work

  • Property mode set to 100644
File size: 14.8 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
25var vI = {
26    preferences : Components.classes["@mozilla.org/preferences-service;1"]
27            .getService(Components.interfaces.nsIPrefService)
28            .getBranch("extensions.virtualIdentity."),
29   
30    headerParser : Components.classes["@mozilla.org/messenger/headerparser;1"]
31                .getService(Components.interfaces.nsIMsgHeaderParser),
32   
33    unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
34                .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
35
36    gMsgCompose : null, // to store the global gMsgCompose after MsgComposeDialog is closed
37
38    // Those variables keep pointers to original functions which might get replaced later
39    original_functions : {
40        GenericSendMessage : null,
41        FillIdentityListPopup : null,   // TB 2.x
42        FillIdentityList : null     // TB 3.x
43    },
44
45    // some pointers to the layout-elements of the extension
46    elements : {
47        init_base : function() {
48            vI.elements.Area_MsgIdentityHbox = document.getElementById("msgIdentityHbox");
49            vI.elements.Obj_MsgIdentity = document.getElementById("msgIdentity");
50        },
51        init_rest : function() {
52            vI.elements.Obj_MsgIdentityPopup = document.getElementById("msgIdentityPopup");
53            vI.elements.Obj_vILogo = document.getElementById("v_identity_logo");
54            vI.elements.strings = document.getElementById("vIdentBundle");
55        },
56        strings : null
57    },
58
59    ComposeStateListener : {
60        NotifyComposeBodyReady: function() { 
61            vI_notificationBar.dump("## v_identity: NotifyComposeBodyReady\n");
62            if (!vI_helper.olderVersion("TB", "2.0a")) vI.initSystemStage2();
63        },
64        NotifyComposeFieldsReady: function() { 
65            vI_notificationBar.dump("## v_identity: NotifyComposeFieldsReady\n");
66            if (vI_helper.olderVersion("TB", "2.0a")) vI.initSystemStage2();
67        },
68        ComposeProcessDone: function(aResult) {
69            vI_notificationBar.dump("## v_identity: StateListener reports ComposeProcessDone\n");
70            vI.Cleanup(); // not really required, parallel handled by vI.close
71            vI_storage.clean();
72        },
73        SaveInFolderDone: function(folderURI) { 
74            vI_notificationBar.dump("## v_identity: SaveInFolderDone\n");
75            vI.Cleanup();
76            vI_storage.clean();
77        }
78    },
79       
80    replacement_functions : {
81        // TB 2.x
82        FillIdentityListPopup: function(popup) {
83            vI_notificationBar.dump("## v_identity: mod. FillIdentityListPopup\n");
84            var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount);
85            accounts.sort(compareAccountSortOrder);
86
87            for (var i in accounts) {
88                var server = accounts[i].incomingServer;
89                if (!server) continue;
90                // check for VirtualIdentity Account
91                try {   vI_account.prefroot.getBoolPref("mail.account." + accounts[i].key + ".vIdentity");
92                    continue; } catch (e) { };
93
94                var identities = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity);
95                for (var j in identities) {
96                    var identity = identities[j];
97                    var item = document.createElement("menuitem");
98                    item.className = "identity-popup-item";
99                    item.setAttribute("label", identity.identityName);
100                    item.setAttribute("value", identity.key);
101                    item.setAttribute("accountkey", accounts[i].key);
102                    item.setAttribute("accountname", " - " + server.prettyName);
103                    popup.appendChild(item);
104                }
105            }
106        },
107       
108        // TB 3.x
109        FillIdentityList: function(menulist) {
110            vI_notificationBar.dump("## v_identity: mod. FillIdentityList\n");
111            var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount);
112            if (typeof(sortAccounts)=="function") // TB 3.x
113                accounts.sort(sortAccounts);
114
115            for (var i in accounts) {
116                var server = accounts[i].incomingServer;
117                if (!server) continue;
118                // check for VirtualIdentity Account
119                try {   vI_account.prefroot.getBoolPref("mail.account." + accounts[i].key + ".vIdentity");
120                    continue; } catch (e) { };
121
122                var identities = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity);
123                for (var j in identities) {
124                    var identity = identities[j];
125                    var item = menulist.appendItem(identity.identityName, identity.key, server.prettyName);
126                    item.setAttribute("accountkey", accounts[i].key);
127                }
128            }
129        },
130       
131        GenericSendMessageInProgress : false,
132        GenericSendMessage: function (msgType) {
133            if (vI.replacement_functions.GenericSendMessageInProgress) return;
134            vI.replacement_functions.GenericSendMessageInProgress = true;
135           
136            var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
137                .getService(Components.interfaces.nsIPromptService);
138            vI_notificationBar.dump("\n## v_identity: VIdentity_GenericSendMessage\n");
139           
140            var vid = document.getElementById("msgIdentity_clone").vid
141
142            if (msgType != nsIMsgCompDeliverMode.Now) {
143                // dont allow user to fake identity if Message is not sended NOW and thunderbird-version is below 2.0 !!!!
144                if (vid && (vI_helper.olderVersion("TB", "2.0b") || vI_helper.olderVersion("SM", "1.5a"))) {
145                    var server = gAccountManager.defaultAccount.incomingServer.prettyName
146                    var name = gAccountManager.defaultAccount.defaultIdentity.fullName
147                    var email = gAccountManager.defaultAccount.defaultIdentity.email
148                    var query = vI.elements.strings.getString("vident.sendLater.warning") +
149                        vI.elements.strings.getString("vident.sendLater.prefix") +
150                        name + " " + email + " [" + server + "]" + 
151                        vI.elements.strings.getString("vident.sendLater.postfix")
152                   
153                    if (!promptService.confirm(window,"Error",query)) {
154                        vI.replacement_functions.GenericSendMessageInProgress = false;
155                        return;
156                    }
157                    else { document.getElementById("msgIdentity_clone").selectedMenuItem = "default"; vid = false; }
158                }
159            }
160            else {
161                if ( (vid && vI.preferences.getBoolPref("warn_virtual") &&
162                    !(promptService.confirm(window,"Warning",
163                        vI.elements.strings.getString("vident.sendVirtual.warning")))) ||
164                  (!vid && vI.preferences.getBoolPref("warn_nonvirtual") &&
165                    !(promptService.confirm(window,"Warning",
166                        vI.elements.strings.getString("vident.sendNonvirtual.warning")))) ) {
167                    vI.replacement_functions.GenericSendMessageInProgress = false;
168                    return;
169                }
170                if (!vI_storage.storeVIdentityToAllRecipients(msgType)) {
171//                  vI_notificationBar.dump("## v_identity: sending aborted\n");
172                    vI.replacement_functions.GenericSendMessageInProgress = false;
173                    return;
174                }
175                vI_msgIdentityCloneTools.addReplyToSelf();
176            }
177            if (vid) vI.prepareAccount();
178            vI.replacement_functions.GenericSendMessageInProgress = false;
179//          vI_notificationBar.dump("## v_identity: original_functions.GenericSendMessage\n");
180            vI.original_functions.GenericSendMessage(msgType);
181
182//          vI_notificationBar.dump("## v_identity: original_functions.GenericSendMessage done\n");
183        },
184       
185        replace_FillIdentityList : function() {
186            if (typeof(FillIdentityList)=="function") {
187                //~ vI_notificationBar.dump("## v_identity: replace FillIdentityList (TB 3.x)\n");
188                vI.original_functions.FillIdentityList = FillIdentityList;
189                FillIdentityList = vI.replacement_functions.FillIdentityList;
190            }
191            else {
192                //~ vI_notificationBar.dump("## v_identity: replace FillIdentityListPopup (TB 2.x)\n");
193                vI.original_functions.FillIdentityListPopup = FillIdentityListPopup;
194                FillIdentityListPopup = vI.replacement_functions.FillIdentityListPopup;
195            }
196        }
197    },
198
199    remove: function() {
200        window.removeEventListener('compose-window-reopen', vI.reopen, true);
201        window.removeEventListener('compose-window-close', vI.close, true);
202        vI_notificationBar.dump("## v_identity: end. remove Account if there.\n")
203        vI.Cleanup();
204        vI_storage.clean();
205    },
206
207    // initialization //
208    init: function() {
209        window.removeEventListener('load', vI.init, false);
210        window.removeEventListener('compose-window-init', vI.init, true);
211        if (vI.elements.Area_MsgIdentityHbox) return; // init done before, (?reopen)
212        vI_notificationBar.dump("\n## v_identity: init.\n")
213        vI.unicodeConverter.charset="UTF-8";
214        vI.adapt_interface();
215        vI.adapt_genericSendMessage();
216        gMsgCompose.RegisterStateListener(vI.ComposeStateListener);
217        document.getElementById("vI_tooltipPopupset")
218            .addTooltip(document.getElementById("msgIdentity_clone"), false);
219        window.addEventListener('compose-window-reopen', vI.reopen, true);
220        window.addEventListener('compose-window-close', vI.close, true);
221       
222        // append observer to fcc_switch, because it does'n work with real identities (hidden by css)
223        document.getElementById("fcc_switch").appendChild(document.getElementById("msgIdentity_clone_observer").cloneNode(false));
224
225        vI.initSystemStage1();
226        vI_notificationBar.dump("## v_identity: init done.\n\n")
227    },
228   
229    initSystemStage1 : function() {
230        vI_notificationBar.dump("## v_identity: initSystemStage1.\n")
231        vI.gMsgCompose = gMsgCompose;
232        document.getElementById("msgIdentity_clone").init();
233        vI_statusmenu.init();
234    },
235   
236    initSystemStage2 : function() {
237        vI_notificationBar.dump("## v_identity: initSystemStage2.\n")
238        vI_msgIdentityCloneTools.initReplyTo();
239        vI_storage.init();
240        vI_smartIdentity.init();
241    },
242   
243    close : function() {
244        vI.Cleanup();
245        vI_storage.clean();
246    },
247   
248    adapt_interface : function() {
249        if (vI.elements.strings) return; // only rearrange the interface once
250       
251        // initialize the pointers to extension elements
252        vI.elements.init_base()
253       
254        // rearrange the positions of some elements
255        var parent_hbox = vI.elements.Obj_MsgIdentity.parentNode;
256        var storage_box = document.getElementById("addresses-box");
257        var autoReplyToSelfLabel = document.getElementById("autoReplyToSelfLabel");
258       
259        storage_box.removeChild(autoReplyToSelfLabel);
260        parent_hbox.appendChild(autoReplyToSelfLabel);
261        storage_box.removeChild(vI.elements.Area_MsgIdentityHbox);
262        parent_hbox.appendChild(vI.elements.Area_MsgIdentityHbox);
263
264        vI.elements.Obj_MsgIdentity.setAttribute("hidden", "true");
265        vI.elements.Obj_MsgIdentity.previousSibling.setAttribute("control", "msgIdentity_clone");
266       
267        // initialize the pointers to extension elements (initialize those earlier might brake the interface)
268        vI.elements.init_rest();   
269    },
270   
271    adapt_genericSendMessage : function() {
272        if (vI.original_functions.GenericSendMessage) return; // only initialize this once
273        vI_notificationBar.dump("## v_identity: adapt GenericSendMessage\n");
274        vI.original_functions.GenericSendMessage = GenericSendMessage;
275        GenericSendMessage = vI.replacement_functions.GenericSendMessage;
276    },
277   
278    reopen: function() {
279        vI_notificationBar.clear();
280        vI_notificationBar.clear_dump();
281        vI_notificationBar.dump("## v_identity: composeDialog reopened. (msgType " + gMsgCompose.type + ")\n")
282       
283        // clean all elements
284        document.getElementById("msgIdentity_clone").clean();
285        vI_smartIdentity.clean();
286        vI_notificationBar.dump("## v_identity: everything cleaned.\n")
287       
288        // now (re)init the elements
289        vI.initSystemStage1();
290       
291        // stateListener only works in reply-cases
292        // so activate stage2 in reply-cases trough StateListener
293        // in other cases directly
294        var msgComposeType = Components.interfaces.nsIMsgCompType;
295        switch (gMsgCompose.type) {
296            case msgComposeType.New:
297            case msgComposeType.NewsPost:
298            case msgComposeType.MailToUrl:
299            case msgComposeType.Draft:
300            case msgComposeType.Template:
301            case msgComposeType.ForwardAsAttachment:
302            case msgComposeType.ForwardInline:
303                vI.initSystemStage2(); break;
304            case msgComposeType.Reply:
305            case msgComposeType.ReplyAll:
306            case msgComposeType.ReplyToGroup:
307            case msgComposeType.ReplyToSender:
308            case msgComposeType.ReplyToSenderAndGroup:
309            case msgComposeType.ReplyWithTemplate:
310                gMsgCompose.RegisterStateListener(vI.ComposeStateListener);
311        }
312        vI_notificationBar.dump("## v_identity: reopen done.\n")
313    },
314   
315    tempStorage: { BaseIdentity : null, NewIdentity : null },
316
317    __setSelectedIdentity : function(menuItem) {
318        vI.elements.Obj_MsgIdentity.selectedItem = menuItem;
319        vI.elements.Obj_MsgIdentity.setAttribute("label", menuItem.getAttribute("label"));
320        vI.elements.Obj_MsgIdentity.setAttribute("accountname", menuItem.getAttribute("accountname"));
321        vI.elements.Obj_MsgIdentity.setAttribute("value", menuItem.getAttribute("value"));
322    },
323
324    // sets the values of the dropdown-menu to the ones of the newly created account
325    addVirtualIdentityToMsgIdentityMenu : function()
326    {
327        vI.tempStorage.BaseIdentity = vI.elements.Obj_MsgIdentity.selectedItem;
328        vI.tempStorage.NewIdentity = document.createElement("menuitem");
329        vI.tempStorage.NewIdentity.className = "identity-popup-item";
330       
331        // set the account name in the choosen menu item
332        vI.tempStorage.NewIdentity.setAttribute("label", vI_account.account.defaultIdentity.identityName);
333        vI.tempStorage.NewIdentity.setAttribute("accountname", " - " +  vI_account.account.incomingServer.prettyName);
334        vI.tempStorage.NewIdentity.setAttribute("accountkey", vI_account.account.key);
335        vI.tempStorage.NewIdentity.setAttribute("value", vI_account.account.defaultIdentity.key);
336       
337        vI.elements.Obj_MsgIdentityPopup.appendChild(vI.tempStorage.NewIdentity);
338        vI.__setSelectedIdentity(vI.tempStorage.NewIdentity);
339    },
340   
341    removeVirtualIdentityFromMsgIdentityMenu : function()
342    {
343        if (!vI.tempStorage.BaseIdentity) return; // don't try to remove Item twice
344        try {   // might not exist anymore (window closed), so just try to remove it
345            document.getElementById("msgIdentity").firstChild.removeChild(vI.tempStorage.NewIdentity);
346            vI.__setSelectedIdentity(vI.tempStorage.BaseIdentity);
347        } catch (e) { };
348        vI.tempStorage.NewIdentity = null;
349        vI.tempStorage.BaseIdentity = null;
350    },
351
352    prepareAccount : function() {
353        vI.Cleanup(); // just to be sure that nothing is left (maybe last time sending was irregularily stopped)
354        vI_account.createAccount();
355        vI.addVirtualIdentityToMsgIdentityMenu();
356    },
357
358    Cleanup : function() {
359        vI.removeVirtualIdentityFromMsgIdentityMenu();
360        vI_account.removeUsedVIAccount();
361    }
362}
363
364
365vI.replacement_functions.replace_FillIdentityList();
366window.addEventListener('load', vI.init, false);        // TB 1.5x, SM
367window.addEventListener('compose-window-init', vI.init, true);  // TB 2.x 3.x
368
369window.addEventListener("unload", function(e) { try {vI_statusmenu.removeObserver();} catch (ex) { } }, false);
370
Note: See TracBrowser for help on using the repository browser.