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 @ 08cca0

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

prevent adding incomingserver to RDF

  • Property mode set to 100644
File size: 15.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_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        var mailWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService()
188            .QueryInterface(Components.interfaces.nsIWindowMediator)
189            .getMostRecentWindow("mail:3pane");
190        var selectedFolder = (mailWindow.gFolderTreeView)?mailWindow.gFolderTreeView.getSelectedFolders()[0]:null;
191        var selectedMessages = (mailWindow.gFolderDisplay)?mailWindow.gFolderDisplay.selectedMessages:null;
192        if (vI_account.account) {
193            vI_account.__removeAccount(vI_account.account);
194            vI_account.account = null;
195        }
196        try {
197        if (selectedFolder) mailWindow.gFolderTreeView.selectFolder(selectedFolder);
198        if (selectedMessages) mailWindow.gFolderDisplay.selectMessages(selectedMessages, false, false);
199        } catch (e) { };
200    },
201   
202    createAccount : function()
203    {
204        if (vI_account.account) {  // if the Account is still created, then leave all like it is
205            alert("account still created, shouldn't happen");
206            return;
207        }
208        /*
209        // the easiest way would be to get all requiered Attributes might be to duplicate the default account like this
210        var recentAccount = vI_account.AccountManager.getAccount(vI.elements.Obj_MsgIdentity.selectedItem.getAttribute("accountkey"));
211        vI.VIdent_Account = vI_account.AccountManager.duplicateAccount(recentAccount);
212        // but this ends up in the following exception:
213        // "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIMsgAccountManager.duplicateAccount]"
214        // so I have to do this by hand ;(
215        */
216       
217        vI_account.account = vI_account.AccountManager.createAccount();
218        vI_account.prefroot.setBoolPref("mail.account." + vI_account.account.key + ".vIdentity", true)
219       
220        vI_account.account.addIdentity(vI_account.AccountManager.createIdentity());
221   
222        // the new account uses the same incomingServer than the base one,
223        // it's especially required for NNTP cause incomingServer is used for sending newsposts.
224        // by pointing to the same incomingServer stored passwords can be reused
225        // the incomingServer has to be replaced before the account is removed, else it get removed ether
226        var servers = vI_account.AccountManager.GetServersForIdentity(vI_account._getBaseIdentity());
227        var server = servers.QueryElementAt(0, Components.interfaces.nsIMsgIncomingServer);
228       
229        // we mark the server as invalid so that the account manager won't
230        // tell RDF about the new server - we don't need this server for long
231        // but we should restore it, because it's actually the same server as the one of the base identity
232        server.valid = false;
233        vI_account.account.incomingServer = server;
234        server.valid = true;
235
236        vI_account.copyMsgIdentityClone();
237        vI_account.copyPreferences();
238        vI_account.setupFcc();
239        vI_account.setupDraft();
240        vI_account.setupTemplates();
241    },
242   
243    copyMsgIdentityClone : function() {
244        var identityData = document.getElementById("msgIdentity_clone").identityData;
245        vI_account.account.defaultIdentity.setCharAttribute("useremail", identityData.email);
246        vI_account.account.defaultIdentity.setUnicharAttribute("fullName", identityData.fullName);
247       
248        vI_account.account.defaultIdentity.smtpServerKey = identityData.smtp.keyNice; // key with "" for DEFAULT_SMTP_TAG
249
250        vI_notificationBar.dump("## vI_account: Stored virtualIdentity (name "
251            + vI_account.account.defaultIdentity.fullName + " email "
252            + vI_account.account.defaultIdentity.email + " smtp "
253            + vI_account.account.defaultIdentity.smtpServerKey +")\n");
254    },
255   
256    setupFcc : function()
257    {
258        if (document.getElementById("fcc_switch").getAttribute("checked")) {
259            switch (vI.preferences.getCharPref("fccFolderPickerMode"))
260            {
261                case "2"  :
262                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Settings of Default Account\n");
263                vI_account.account.defaultIdentity.doFcc = vI_account.AccountManager.defaultAccount.defaultIdentity.doFcc;
264                vI_account.account.defaultIdentity.fccFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.fccFolder;
265                vI_account.account.defaultIdentity.fccFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.fccFolderPickerMode;
266                if (!vI_helper.olderVersion("TB", "2.0"))
267                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI_account.AccountManager.defaultAccount.defaultIdentity.fccReplyFollowsParent;
268                break;
269                case "3"  :
270                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Settings of Modified Account\n");
271                vI_account.account.defaultIdentity.doFcc = vI_account._getBaseIdentity().doFcc;
272                vI_account.account.defaultIdentity.fccFolder = vI_account._getBaseIdentity().fccFolder;
273                vI_account.account.defaultIdentity.fccFolderPickerMode = vI_account._getBaseIdentity().fccFolderPickerMode;
274                if (!vI_helper.olderVersion("TB", "2.0"))
275                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI_account._getBaseIdentity().fccReplyFollowsParent;
276                break;
277                default  :
278                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Virtual Identity Settings\n");
279                vI_account.account.defaultIdentity.doFcc
280                    = vI.preferences.getBoolPref("doFcc");
281                vI_account.account.defaultIdentity.fccFolder
282                    = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("fccFolder"));
283                vI_account.account.defaultIdentity.fccFolderPickerMode
284                    = vI.preferences.getCharPref("fccFolderPickerMode");
285                if (!vI_helper.olderVersion("TB", "2.0"))
286                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI.preferences.getBoolPref("fccReplyFollowsParent");
287
288                break;
289            }
290        }
291        else {
292            dump ("## vI_account: dont performing Fcc\n");
293            vI_account.account.defaultIdentity.doFcc = false;
294        }
295        vI_notificationBar.dump("## vI_account: Stored (doFcc " + vI_account.account.defaultIdentity.doFcc + " fccFolder " +
296            vI_account.account.defaultIdentity.fccFolder + " fccFolderPickerMode " +
297            vI_account.account.defaultIdentity.fccFolderPickerMode + "(" +
298            vI.preferences.getCharPref("fccFolderPickerMode") + "))\n");
299    },
300   
301    setupDraft : function() {
302        switch (vI.preferences.getCharPref("draftFolderPickerMode"))
303        {
304            case "2"  :
305            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Settings of Default Account\n");
306            vI_account.account.defaultIdentity.draftFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.draftFolder;
307            vI_account.account.defaultIdentity.draftsFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.draftsFolderPickerMode;
308            break;
309            case "3"  :
310            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Settings of Modified Account\n");
311            vI_account.account.defaultIdentity.draftFolder = vI_account._getBaseIdentity().draftFolder;
312            vI_account.account.defaultIdentity.draftsFolderPickerMode = vI_account._getBaseIdentity().draftsFolderPickerMode;
313            break;
314            default  :
315            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Virtual Identity Settings\n");
316            vI_account.account.defaultIdentity.draftFolder
317                = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("draftFolder"));
318            vI_account.account.defaultIdentity.draftsFolderPickerMode
319                = vI.preferences.getCharPref("draftFolderPickerMode");
320            break;
321        }
322        vI_notificationBar.dump("## vI_account: Stored (draftFolder " +
323            vI_account.account.defaultIdentity.draftFolder + " draftsFolderPickerMode " +
324            vI_account.account.defaultIdentity.draftsFolderPickerMode + "(" +
325            vI.preferences.getCharPref("draftFolderPickerMode") + "))\n");
326    },
327   
328    setupTemplates : function() {
329        switch (vI.preferences.getCharPref("stationeryFolderPickerMode"))
330        {
331            case "2"  :
332            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Settings of Default Account\n");
333            vI_account.account.defaultIdentity.stationeryFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.stationeryFolder;
334            vI_account.account.defaultIdentity.tmplFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.tmplFolderPickerMode;
335            break;
336            case "3"  :
337            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Settings of Modified Account\n");
338            vI_account.account.defaultIdentity.stationeryFolder = vI_account._getBaseIdentity().stationeryFolder;
339            vI_account.account.defaultIdentity.tmplFolderPickerMode = vI_account._getBaseIdentity().tmplFolderPickerMode;
340            break;
341            default  :
342            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Virtual Identity Settings\n");
343            vI_account.account.defaultIdentity.stationeryFolder
344                = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("stationeryFolder"));
345            vI_account.account.defaultIdentity.tmplFolderPickerMode
346                = vI.preferences.getCharPref("stationeryFolderPickerMode");
347            break;
348        }
349        vI_notificationBar.dump("## vI_account: Stored (stationeryFolder " +
350            vI_account.account.defaultIdentity.stationeryFolder + " tmplFolderPickerMode " +
351            vI_account.account.defaultIdentity.tmplFolderPickerMode + "(" +
352            vI.preferences.getCharPref("stationeryFolderPickerMode") + "))\n");
353    }
354}
Note: See TracBrowser for help on using the repository browser.