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 @ 9e9bab

Last change on this file since 9e9bab was 9e9bab, checked in by root <root@…>, 15 years ago

initial import v0.4.0

  • Property mode set to 100644
File size: 11.4 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    helper : {
27        // "accountname" property changed in Thunderbird 3.x, Seamonkey 1.5x to "description"
28        getAccountname: function(elem) {
29            if (elem.getAttribute("accountname") == "" && elem.getAttribute("description") != "")
30                return "- " + elem.getAttribute("description")
31            else return elem.getAttribute("accountname")
32        },
33
34        addIdentityMenuItem: function(object, identityName, accountName, accountKey, identityKey) {
35            var MenuItem = document.createElement("menuitem");
36            MenuItem.className = "identity-popup-item";
37           
38            // set the account name in the choosen menu item
39            MenuItem.setAttribute("label", identityName);
40            MenuItem.setAttribute("accountname", accountName);
41            MenuItem.setAttribute("accountkey", accountKey);
42            MenuItem.setAttribute("value", identityKey);
43            MenuItem.setAttribute("class", "identity_clone-popup-item new-icon")
44           
45            object.appendChild(MenuItem)
46           
47            return MenuItem
48        },
49
50        selectIdentityMenuItem: function(object, MenuItem) {
51            object.selectedItem = MenuItem;
52            // set the account name on the menu list value.
53            object.setAttribute("label", MenuItem.getAttribute("label"));
54            object.setAttribute("accountname", MenuItem.getAttribute("accountname"));
55            object.setAttribute("accountkey", MenuItem.getAttribute("accountkey"));
56            object.setAttribute("value", MenuItem.getAttribute("value"));
57        },
58
59        addSeparatorToCloneMenu: function() {
60            var object = vI_msgIdentityClone.elements.Obj_msgIdentityClone;
61            var separator = document.createElement("menuseparator");
62            separator.setAttribute("id", "vid_separator");
63            vI_msgIdentityClone.elements.Obj_MsgIdentityPopup_clone.appendChild(
64                separator)
65        },
66
67        getBaseIdentity : function () {
68            return gAccountManager.getIdentity(vI.elements.Obj_MsgIdentity.value);
69        },
70       
71        getAddress : function() {
72            var address = vI_msgIdentityClone.elements.Obj_MsgIdentityTextbox_clone.value;
73            var splitted = { number : 0, emails : {}, fullNames : {}, combinedNames : {} };
74            vI.headerParser .parseHeadersWithArray(address, splitted.emails,
75                splitted.fullNames, splitted.combinedNames);
76            return { name: splitted.fullNames.value[0], email: splitted.emails.value[0],
77                    combinedName: splitted.combinedNames.value[0]}
78        },
79    },
80
81    preferences : Components.classes["@mozilla.org/preferences-service;1"]
82            .getService(Components.interfaces.nsIPrefService)
83            .getBranch("extensions.virtualIdentity."),
84   
85    headerParser : Components.classes["@mozilla.org/messenger/headerparser;1"]
86                .getService(Components.interfaces.nsIMsgHeaderParser),
87   
88    params : window.arguments[0],
89
90    // Those variables keep pointers to original functions which might get replaced later
91    original_functions : {
92        GenericSendMessage : null,
93        MsgComposeCloseWindow : null,
94    },
95
96    // some pointers to the layout-elements of the extension
97    elements : {
98        init_base : function() {
99            vI.elements.Area_MsgIdentityHbox = document.getElementById("msgIdentityHbox");
100            vI.elements.Obj_MsgIdentity = document.getElementById("msgIdentity");
101        },
102        init_rest : function() {
103            vI.elements.Obj_MsgIdentityPopup = document.getElementById("msgIdentityPopup");
104            vI.elements.Obj_vILogo = document.getElementById("v_identity_logo");
105            vI.elements.strings = document.getElementById("vIdentBundle");
106        },
107    },
108
109    ComposeStateListener : {
110        NotifyComposeBodyReady: function() { 
111            vI_notificationBar.dump("## v_identity: NotifyComposeBodyReady\n");
112        },
113        NotifyComposeFieldsReady: function() { 
114            vI_notificationBar.dump("## v_identity: NotifyComposeFieldsReady\n");
115            vI_smartIdentity.init();
116        },
117        ComposeProcessDone: function(aResult) {
118            vI_notificationBar.dump("## v_identity: StateListener reports ComposeProcessDone\n");
119            vI.Cleanup_Account();
120            if (aResult== Components.results.NS_OK && vI.msgType == nsIMsgCompDeliverMode.Now)
121                    MsgComposeCloseWindow(false); // on TB 1.5* window is otherwise really closed, only hidden
122        },
123        SaveInFolderDone: function(folderURI) { 
124            vI_notificationBar.dump("## v_identity: SaveInFolderDone\n");
125            vI.Cleanup_Account();
126        }
127    },
128   
129    replacement_functions : {
130        // if the windows gets closed, this is the way to get rid of the account.
131        MsgComposeCloseWindow : function(recycleIt) {
132            vI_notificationBar.dump("## v_identity: MsgComposeCloseWindow\n");
133            vI.original_functions.MsgComposeCloseWindow(false);
134        },
135
136        GenericSendMessage: function (msgType) {
137            vI_notificationBar.dump("## v_identity: VIdentity_GenericSendMessage\n");
138
139            // dont allow user to fake identity if Message is not sended NOW and thunderbird-version is below 2.0 !!!!
140            var appInfo = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);
141            var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"].getService(Components.interfaces.nsIVersionComparator);
142            const THUNDERBIRD_ID = "{3550f703-e582-4d05-9a08-453d09bdfdc6}";
143            //const MOZILLA_ID = "{86c18b42-e466-45a9-ae7a-9b95ba6f5640}";
144            const SEAMONKEY_ID = "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}";
145            if (msgType != nsIMsgCompDeliverMode.Now &&
146                ((appInfo.ID == THUNDERBIRD_ID && versionChecker.compare(appInfo.version, "2.0b") < 0) ||
147                (appInfo.ID == SEAMONKEY_ID && versionChecker.compare(appInfo.version, "1.5a") < 0)))   {
148                var server = gAccountManager.defaultAccount.incomingServer.prettyName
149                var name = gAccountManager.defaultAccount.defaultIdentity.fullName
150                var email = gAccountManager.defaultAccount.defaultIdentity.email
151
152                //Get the bundled string file.
153                var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
154                    .getService(Components.interfaces.nsIPromptService);
155                if (promptService.confirm(window,"Error",vI.elements.strings.getString("vident.sendLater.warning") +
156                    vI.elements.strings.getString("vident.sendLater.prefix") +
157                    name + " " + email + " [" + server + "]" + vI.elements.strings.getString("vident.sendLater.postfix")))
158                    {
159                        vI_msgIdentityClone.resetMenuToDefault();
160                        GenericSendMessage( msgType );
161                    }
162                else { return; }
163            }
164            else {
165                vI_account.createAccount();
166                vI.addVirtualIdentityToMsgIdentityMenu();
167                vI.msgType = msgType; // store msgType to know if window should be closed or not
168               
169                vI.original_functions.GenericSendMessage( msgType );
170                if (window.cancelSendMessage) {
171                    vI.Cleanup_Account();
172                    vI_notificationBar.dump("## v_identity: SendMessage cancelled\n");
173                }
174            }
175        },
176
177        replaceGenericFunction : function()
178        {
179            if (vI.original_functions.GenericSendMessage) return true;
180            if (typeof(GenericSendMessage)=="function") {
181                vI_notificationBar.dump("## v_identity: replace GenericSendMessage\n");
182                vI.original_functions.GenericSendMessage = GenericSendMessage;
183                GenericSendMessage = function (msgType) {
184                    vI.replacement_functions.GenericSendMessage(msgType);}
185                return true;
186            }
187            else {
188                vI_notificationBar.dump("## v_identity ERROR: could not replace your SendMessage Function, aborting\n"); 
189                return false;
190            }
191        },
192    },
193
194    remove: function() {
195        vI_notificationBar.dump("## v_identity: end. remove Account if there.\n")
196        vI.Cleanup_Account();
197    },
198   
199    // initialization //
200    init: function() {
201        // initialize the pointers to extension elements
202        vI.elements.init_base()
203       
204        // rearrange the positions of some elements
205        var parent_hbox = vI.elements.Obj_MsgIdentity.parentNode;
206        var storage_box = document.getElementById("addresses-box");
207       
208        storage_box.removeChild(vI.elements.Area_MsgIdentityHbox)
209        parent_hbox.appendChild(vI.elements.Area_MsgIdentityHbox);
210       
211        vI.elements.Obj_MsgIdentity.setAttribute("hidden", "true");
212       
213        // initialize the pointers to extension elements (initialize those earlier might brake the interface)
214        vI.elements.init_rest();
215       
216        vI_smtpSelector.init();
217        vI_msgIdentityClone.init();
218       
219        // replace MsgComposeCloseWindow with our own version to get rid of the old account in any case
220        vI_notificationBar.dump("## v_identity: replace MsgComposeCloseWindow\n");
221        vI.original_functions.MsgComposeCloseWindow = MsgComposeCloseWindow;
222        MsgComposeCloseWindow = function (recycleIt) {
223            vI.replacement_functions.MsgComposeCloseWindow(recycleIt); }
224       
225        gMsgCompose.RegisterStateListener(vI.ComposeStateListener);
226        window.removeEventListener("load", vI.init, false);
227    },
228   
229    // sets the values of the dropdown-menu to the ones of the newly created account
230    addVirtualIdentityToMsgIdentityMenu : function()
231    {
232        vI.storeBaseIdentity = {
233            label : vI.elements.Obj_MsgIdentity.getAttribute("label"),
234            accountname : vI.elements.Obj_MsgIdentity.getAttribute("accountname"),
235            accountkey : vI.elements.Obj_MsgIdentity.getAttribute("accountkey"),
236            value : vI.elements.Obj_MsgIdentity.getAttribute("value")
237        }
238        var newMenuItem = vI.helper.addIdentityMenuItem(vI.elements.Obj_MsgIdentityPopup,
239                        vI_account.account.defaultIdentity.identityName,
240                        " - " +  vI_account.account.incomingServer.prettyName,
241                        vI_account.account.key,
242                        vI_account.account.defaultIdentity.key)
243        vI.helper.selectIdentityMenuItem(vI.elements.Obj_MsgIdentity, newMenuItem)
244    },
245   
246    // sets the values of the dropdown-menu to the ones of the newly created account
247    remVirtualIdentityFromMsgIdentityMenu : function()
248    {
249        MenuItems = vI_msgIdentityClone.elements.Obj_MsgIdentity.firstChild.childNodes
250        for (index = 0; index < MenuItems.length; index++) {
251            if ( MenuItems[index].getAttribute("value") == vI_account.account.defaultIdentity.key )
252                vI_msgIdentityClone.elements.Obj_MsgIdentity.firstChild.removeChild(MenuItems[index])
253        }
254        vI.elements.Obj_MsgIdentity.setAttribute("label", vI.storeBaseIdentity.label);
255        vI.elements.Obj_MsgIdentity.setAttribute("accountname", vI.storeBaseIdentity.accountname);
256        vI.elements.Obj_MsgIdentity.setAttribute("accountkey", vI.storeBaseIdentity.accountkey);
257        vI.elements.Obj_MsgIdentity.setAttribute("value", vI.storeBaseIdentity.value);
258    },
259   
260    // Clean all the things I had changed (expecpt the FillIdentityListPopup)
261    Cleanup : function()
262    {
263        vI_notificationBar.dump("## v_identity: Cleanup\n");
264        vI.Cleanup_Account();
265       
266        // restore function
267        if (vI.original_functions.GenericSendMessage) {
268            GenericSendMessage = vI.original_functions.GenericSendMessage;
269            vI.original_functions.GenericSendMessage = null;
270        }
271    },
272
273    // removes the account
274    Cleanup_Account : function() {
275        // remove temporary Account
276        if (vI_account.account) {
277            vI.remVirtualIdentityFromMsgIdentityMenu();
278            vI_account.removeAccount();
279        }
280    },
281}
282
283window.addEventListener("load", vI.init, false);
284window.addEventListener("unload", vI.remove, false);
Note: See TracBrowser for help on using the repository browser.