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

source: chrome/content/v_identity/vI_account.js @ e75da7

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

bugfix for SMTP comparison

  • Property mode set to 100644
File size: 14.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
25var vI_account = {
26    account : null,
27   
28    AccountManager : Components.classes["@mozilla.org/messenger/account-manager;1"]
29        .getService(Components.interfaces.nsIMsgAccountManager),
30
31   
32    prefroot : Components.classes["@mozilla.org/preferences-service;1"]
33        .getService(Components.interfaces.nsIPrefService)
34        .getBranch(null),
35
36    _getBaseIdentity : function () {
37        return gAccountManager.getIdentity(vI.elements.Obj_MsgIdentity.value);
38    },
39
40    _copyBoolAttribute : function(name) {
41        vI_account.account.defaultIdentity.setBoolAttribute(name,
42                vI_account._getBaseIdentity().getBoolAttribute(name));
43    },
44   
45    _copyIntAttribute : function(name) {
46        vI_account.account.defaultIdentity.setIntAttribute(name,
47                vI_account._getBaseIdentity().getIntAttribute(name));
48    },
49
50    _copyCharAttribute : function(name) {
51        vI_account.account.defaultIdentity.setCharAttribute(name,
52                vI_account._getBaseIdentity().getCharAttribute(name));
53    },
54
55    _copyUnicharAttribute : function(name) {
56        vI_account.account.defaultIdentity.setUnicharAttribute(name,
57                vI_account._getBaseIdentity().getUnicharAttribute(name));
58    },
59
60    copyPreferences : function() {
61        if (vI.preferences.getBoolPref("copySMIMESettings")) {
62            // SMIME settings
63            vI_notificationBar.dump("## vI_account: copy S/MIME settings\n")
64            vI_account._copyUnicharAttribute("signing_cert_name");
65            vI_account._copyUnicharAttribute("encryption_cert_name");
66            vI_account._copyIntAttribute("encryptionpolicy");
67        }
68/*      seems not required, encryption happens before Virtual Identity account is created
69        if (vI.preferences.getBoolPref("copyEnigmailSettings")) {
70            // pgp/enigmail settings
71            vI_notificationBar.dump("## vI_account: copy PGP settings\n")
72            vI_account._copyBoolAttribute("pgpSignEncrypted");
73            vI_account._copyBoolAttribute("pgpSignPlain");
74            vI_account._copyBoolAttribute("enablePgp");
75            vI_account._copyIntAttribute("pgpKeyMode");
76            vI_account._copyCharAttribute("pgpkeyId");
77            vI_account._copyIntAttribute("openPgpHeaderMode");
78            vI_account._copyCharAttribute("openPgpUrlName");
79       
80            vI_account._copyIntAttribute("defaultEncryptionPolicy");
81        }   */
82        if (vI.preferences.getBoolPref("copyAttachVCardSettings")) {
83            // attach vcard
84            vI_notificationBar.dump("## vI_account: copy VCard settings\n")
85            vI_account._copyBoolAttribute("attachVCard");
86            vI_account._copyCharAttribute("escapedVCard");
87        }
88    },
89   
90    // checks if directory is empty, not really used
91    // ignores files ending with *.msf, else reports if a non-zero file is found.
92    __dirEmpty : function(directory) {
93        var dirEnumerator = directory.directoryEntries;
94        while (dirEnumerator.hasMoreElements()) {
95            var maildir = dirEnumerator.getNext();
96            maildir.QueryInterface(Components.interfaces.nsIFile);
97            // recurse into all subdirectories
98            if (maildir.isDirectory() &&
99                !vI_account.__dirEmpty(maildir)) return false;
100            // ignore files with ending "*.msf"
101            if (!maildir.path.match(new RegExp(".*\.msf$","i")) &&
102                maildir.fileSize != 0) return false;
103        }
104        return true;
105    },
106
107    __cleanupDirectories : function() {
108        vI_notificationBar.dump("## vI_account: checking for leftover VirtualIdentity directories ")
109
110        var file = Components.classes["@mozilla.org/file/directory_service;1"]
111        .getService(Components.interfaces.nsIProperties)
112            .get("ProfD", Components.interfaces.nsIFile);
113       
114        var fileEnumerator = file.directoryEntries
115        while (fileEnumerator.hasMoreElements()) {
116            var dir = fileEnumerator.getNext()
117            dir.QueryInterface(Components.interfaces.nsIFile);
118            if (dir.path.match(new RegExp("[/\\\\]Mail$","i"))) { // match Windows and Linux/Mac separators
119                var dirEnumerator = dir.directoryEntries
120                while (dirEnumerator.hasMoreElements()) {
121                    var maildir = dirEnumerator.getNext()
122                    maildir.QueryInterface(Components.interfaces.nsIFile);
123                    // match Windows and Linux/Mac separators
124                    if (maildir.path.match(new RegExp("[/\\\\]virtualIdentity.*$","i"))) {
125                        // should be empty, VirtualIdentity never uses those directories
126                        if (vI_account.__dirEmpty(maildir)) {
127                            try {maildir.remove(true)} catch(e) { }
128                            vI_notificationBar.dump("x");
129                        }
130                        else vI_notificationBar.dump(".");
131                       
132                    }
133                }
134            }
135        }
136        vI_notificationBar.dump(" - done\n")
137    },
138   
139    cleanupSystem : function() {
140        vI_notificationBar.dump("## vI_account: checking for leftover VirtualIdentity accounts ")
141        for (var i=0; i < vI_account.AccountManager.accounts.Count(); i++) {
142            var account = vI_account.AccountManager.accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
143            if (vI_account.__isVIdentityAccount(account)) {
144                vI_notificationBar.dump(".")
145                vI_account.__removeAccount(account);
146            }
147        }
148        vI_notificationBar.dump(" - done\n")
149        vI_account.__cleanupDirectories();
150    },
151   
152    __isVIdentityAccount : function(account) {
153        // check for new (post0.5.0) accounts,
154        try {   vI_account.prefroot.getBoolPref("mail.account." + account.key + ".vIdentity");
155            return true;
156        } catch (e) { };
157        // check for old (pre 0.5.0) accounts
158        if (account.incomingServer && account.incomingServer.hostName == "virtualIdentity") return true;
159        return false;
160    },
161   
162    __removeAccount : function(account) {
163        // in new (post 0.5.0) Virtual Identity accounts the incomingServer of the account
164        // points to an incoming server of a different account. Cause the internal
165        // removeAccount function tries to removes the incomingServer ether, create
166        // a real one before calling this function.
167        if (!account.incomingServer || account.incomingServer.hostName != "virtualIdentity") {
168            // if not some of the 'old' accounts
169            account.incomingServer = vI_account.AccountManager.
170                createIncomingServer("toRemove","virtualIdentity","pop3");
171        }
172
173        // remove the rootFolder of the account
174        try { account.incomingServer.rootFolder.Delete(); }
175        catch (e) { };
176       
177        var key = account.key;
178        vI_notificationBar.dump("## vI_account: removing account " + key + ".\n")
179        // remove the account
180        vI_account.AccountManager.removeAccount(account);
181        // remove the additional tagging-pref
182        try { vI_account.prefroot.clearUserPref("mail.account." + key + ".vIdentity");  }
183        catch (e) { };
184    },
185   
186    removeUsedVIAccount : function() {
187        if (vI_account.account) {
188            vI_account.__removeAccount(vI_account.account);
189            vI_account.account = null;
190        }
191    },
192   
193    createAccount : function()
194    {
195        if (vI_account.account) {  // if the Account is still created, then leave all like it is
196            alert("account still created, shouldn't happen");
197            return;
198        }
199        /*
200        // the easiest way would be to get all requiered Attributes might be to duplicate the default account like this
201        var recentAccount = vI_account.AccountManager.getAccount(vI.elements.Obj_MsgIdentity.selectedItem.getAttribute("accountkey"));
202        vI.VIdent_Account = vI_account.AccountManager.duplicateAccount(recentAccount);
203        // but this ends up in the following exception:
204        // "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIMsgAccountManager.duplicateAccount]"
205        // so I have to do this by hand ;(
206        */
207       
208        vI_account.account = vI_account.AccountManager.createAccount();
209        vI_account.prefroot.setBoolPref("mail.account." + vI_account.account.key + ".vIdentity", true)
210       
211        vI_account.account.addIdentity(vI_account.AccountManager.createIdentity());
212   
213        // the new account uses the same incomingServer than the base one,
214        // it's especially required for NNTP cause incomingServer is used for sending newsposts.
215        // by pointing to the same incomingServer stored passwords can be reused
216        // the incomingServer has to be replaced before the account is removed, else it get removed ether
217        var servers = vI_account.AccountManager.GetServersForIdentity(vI_account._getBaseIdentity());
218        vI_account.account.incomingServer = servers.QueryElementAt(0, Components.interfaces.nsIMsgIncomingServer);
219       
220        vI_account.copyMsgIdentityClone();
221        vI_account.copyPreferences();
222        vI_account.setupFcc();
223        vI_account.setupDraft();
224        vI_account.setupTemplates();
225    },
226   
227    copyMsgIdentityClone : function() {
228        var identityData = document.getElementById("msgIdentity_clone").identityData;
229        vI_account.account.defaultIdentity.setCharAttribute("useremail", identityData.email);
230        vI_account.account.defaultIdentity.setUnicharAttribute("fullName", identityData.fullName);
231       
232        vI_account.account.defaultIdentity.smtpServerKey = identityData.smtp.keyNice; // key with "" for DEFAULT_SMTP_TAG
233
234        vI_notificationBar.dump("## vI_account: Stored virtualIdentity (name "
235            + vI_account.account.defaultIdentity.fullName + " email "
236            + vI_account.account.defaultIdentity.email + " smtp "
237            + vI_account.account.defaultIdentity.smtpServerKey +")\n");
238    },
239   
240    setupFcc : function()
241    {
242        if (document.getElementById("fcc_switch").getAttribute("checked")) {
243            switch (vI.preferences.getCharPref("fccFolderPickerMode"))
244            {
245                case "2"  :
246                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Settings of Default Account\n");
247                vI_account.account.defaultIdentity.doFcc = vI_account.AccountManager.defaultAccount.defaultIdentity.doFcc;
248                vI_account.account.defaultIdentity.fccFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.fccFolder;
249                vI_account.account.defaultIdentity.fccFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.fccFolderPickerMode;
250                if (!vI_helper.olderVersion("TB", "2.0"))
251                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI_account.AccountManager.defaultAccount.defaultIdentity.fccReplyFollowsParent;
252                break;
253                case "3"  :
254                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Settings of Modified Account\n");
255                vI_account.account.defaultIdentity.doFcc = vI_account._getBaseIdentity().doFcc;
256                vI_account.account.defaultIdentity.fccFolder = vI_account._getBaseIdentity().fccFolder;
257                vI_account.account.defaultIdentity.fccFolderPickerMode = vI_account._getBaseIdentity().fccFolderPickerMode;
258                if (!vI_helper.olderVersion("TB", "2.0"))
259                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI_account._getBaseIdentity().fccReplyFollowsParent;
260                break;
261                default  :
262                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Virtual Identity Settings\n");
263                vI_account.account.defaultIdentity.doFcc
264                    = vI.preferences.getBoolPref("doFcc");
265                vI_account.account.defaultIdentity.fccFolder
266                    = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("fccFolder"));
267                vI_account.account.defaultIdentity.fccFolderPickerMode
268                    = vI.preferences.getCharPref("fccFolderPickerMode");
269                if (!vI_helper.olderVersion("TB", "2.0"))
270                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI.preferences.getBoolPref("fccReplyFollowsParent");
271
272                break;
273            }
274        }
275        else {
276            dump ("## vI_account: dont performing Fcc\n");
277            vI_account.account.defaultIdentity.doFcc = false;
278        }
279        vI_notificationBar.dump("## vI_account: Stored (doFcc " + vI_account.account.defaultIdentity.doFcc + " fccFolder " +
280            vI_account.account.defaultIdentity.fccFolder + " fccFolderPickerMode " +
281            vI_account.account.defaultIdentity.fccFolderPickerMode + "(" +
282            vI.preferences.getCharPref("fccFolderPickerMode") + "))\n");
283    },
284   
285    setupDraft : function() {
286        switch (vI.preferences.getCharPref("draftFolderPickerMode"))
287        {
288            case "2"  :
289            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Settings of Default Account\n");
290            vI_account.account.defaultIdentity.draftFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.draftFolder;
291            vI_account.account.defaultIdentity.draftsFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.draftsFolderPickerMode;
292            break;
293            case "3"  :
294            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Settings of Modified Account\n");
295            vI_account.account.defaultIdentity.draftFolder = vI_account._getBaseIdentity().draftFolder;
296            vI_account.account.defaultIdentity.draftsFolderPickerMode = vI_account._getBaseIdentity().draftsFolderPickerMode;
297            break;
298            default  :
299            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Virtual Identity Settings\n");
300            vI_account.account.defaultIdentity.draftFolder
301                = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("draftFolder"));
302            vI_account.account.defaultIdentity.draftsFolderPickerMode
303                = vI.preferences.getCharPref("draftFolderPickerMode");
304            break;
305        }
306        vI_notificationBar.dump("## vI_account: Stored (draftFolder " +
307            vI_account.account.defaultIdentity.draftFolder + " draftsFolderPickerMode " +
308            vI_account.account.defaultIdentity.draftsFolderPickerMode + "(" +
309            vI.preferences.getCharPref("draftFolderPickerMode") + "))\n");
310    },
311   
312    setupTemplates : function() {
313        switch (vI.preferences.getCharPref("stationeryFolderPickerMode"))
314        {
315            case "2"  :
316            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Settings of Default Account\n");
317            vI_account.account.defaultIdentity.stationeryFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.stationeryFolder;
318            vI_account.account.defaultIdentity.tmplFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.tmplFolderPickerMode;
319            break;
320            case "3"  :
321            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Settings of Modified Account\n");
322            vI_account.account.defaultIdentity.stationeryFolder = vI_account._getBaseIdentity().stationeryFolder;
323            vI_account.account.defaultIdentity.tmplFolderPickerMode = vI_account._getBaseIdentity().tmplFolderPickerMode;
324            break;
325            default  :
326            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Virtual Identity Settings\n");
327            vI_account.account.defaultIdentity.stationeryFolder
328                = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("stationeryFolder"));
329            vI_account.account.defaultIdentity.tmplFolderPickerMode
330                = vI.preferences.getCharPref("stationeryFolderPickerMode");
331            break;
332        }
333        vI_notificationBar.dump("## vI_account: Stored (stationeryFolder " +
334            vI_account.account.defaultIdentity.stationeryFolder + " tmplFolderPickerMode " +
335            vI_account.account.defaultIdentity.tmplFolderPickerMode + "(" +
336            vI.preferences.getCharPref("stationeryFolderPickerMode") + "))\n");
337    }
338}
Note: See TracBrowser for help on using the repository browser.