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 @ 637de5

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

restore FolderDisplay? and FolderTree? - Selections after sending

  • Property mode set to 100644
File size: 15.5 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        vI_account.account.incomingServer = servers.QueryElementAt(0, Components.interfaces.nsIMsgIncomingServer);
228       
229        vI_account.copyMsgIdentityClone();
230        vI_account.copyPreferences();
231        vI_account.setupFcc();
232        vI_account.setupDraft();
233        vI_account.setupTemplates();
234    },
235   
236    copyMsgIdentityClone : function() {
237        var identityData = document.getElementById("msgIdentity_clone").identityData;
238        vI_account.account.defaultIdentity.setCharAttribute("useremail", identityData.email);
239        vI_account.account.defaultIdentity.setUnicharAttribute("fullName", identityData.fullName);
240       
241        vI_account.account.defaultIdentity.smtpServerKey = identityData.smtp.keyNice; // key with "" for DEFAULT_SMTP_TAG
242
243        vI_notificationBar.dump("## vI_account: Stored virtualIdentity (name "
244            + vI_account.account.defaultIdentity.fullName + " email "
245            + vI_account.account.defaultIdentity.email + " smtp "
246            + vI_account.account.defaultIdentity.smtpServerKey +")\n");
247    },
248   
249    setupFcc : function()
250    {
251        if (document.getElementById("fcc_switch").getAttribute("checked")) {
252            switch (vI.preferences.getCharPref("fccFolderPickerMode"))
253            {
254                case "2"  :
255                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Settings of Default Account\n");
256                vI_account.account.defaultIdentity.doFcc = vI_account.AccountManager.defaultAccount.defaultIdentity.doFcc;
257                vI_account.account.defaultIdentity.fccFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.fccFolder;
258                vI_account.account.defaultIdentity.fccFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.fccFolderPickerMode;
259                if (!vI_helper.olderVersion("TB", "2.0"))
260                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI_account.AccountManager.defaultAccount.defaultIdentity.fccReplyFollowsParent;
261                break;
262                case "3"  :
263                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Settings of Modified Account\n");
264                vI_account.account.defaultIdentity.doFcc = vI_account._getBaseIdentity().doFcc;
265                vI_account.account.defaultIdentity.fccFolder = vI_account._getBaseIdentity().fccFolder;
266                vI_account.account.defaultIdentity.fccFolderPickerMode = vI_account._getBaseIdentity().fccFolderPickerMode;
267                if (!vI_helper.olderVersion("TB", "2.0"))
268                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI_account._getBaseIdentity().fccReplyFollowsParent;
269                break;
270                default  :
271                vI_notificationBar.dump ("## vI_account: preparing Fcc --- use Virtual Identity Settings\n");
272                vI_account.account.defaultIdentity.doFcc
273                    = vI.preferences.getBoolPref("doFcc");
274                vI_account.account.defaultIdentity.fccFolder
275                    = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("fccFolder"));
276                vI_account.account.defaultIdentity.fccFolderPickerMode
277                    = vI.preferences.getCharPref("fccFolderPickerMode");
278                if (!vI_helper.olderVersion("TB", "2.0"))
279                    vI_account.account.defaultIdentity.fccReplyFollowsParent = vI.preferences.getBoolPref("fccReplyFollowsParent");
280
281                break;
282            }
283        }
284        else {
285            dump ("## vI_account: dont performing Fcc\n");
286            vI_account.account.defaultIdentity.doFcc = false;
287        }
288        vI_notificationBar.dump("## vI_account: Stored (doFcc " + vI_account.account.defaultIdentity.doFcc + " fccFolder " +
289            vI_account.account.defaultIdentity.fccFolder + " fccFolderPickerMode " +
290            vI_account.account.defaultIdentity.fccFolderPickerMode + "(" +
291            vI.preferences.getCharPref("fccFolderPickerMode") + "))\n");
292    },
293   
294    setupDraft : function() {
295        switch (vI.preferences.getCharPref("draftFolderPickerMode"))
296        {
297            case "2"  :
298            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Settings of Default Account\n");
299            vI_account.account.defaultIdentity.draftFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.draftFolder;
300            vI_account.account.defaultIdentity.draftsFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.draftsFolderPickerMode;
301            break;
302            case "3"  :
303            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Settings of Modified Account\n");
304            vI_account.account.defaultIdentity.draftFolder = vI_account._getBaseIdentity().draftFolder;
305            vI_account.account.defaultIdentity.draftsFolderPickerMode = vI_account._getBaseIdentity().draftsFolderPickerMode;
306            break;
307            default  :
308            vI_notificationBar.dump ("## vI_account: preparing Draft --- use Virtual Identity Settings\n");
309            vI_account.account.defaultIdentity.draftFolder
310                = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("draftFolder"));
311            vI_account.account.defaultIdentity.draftsFolderPickerMode
312                = vI.preferences.getCharPref("draftFolderPickerMode");
313            break;
314        }
315        vI_notificationBar.dump("## vI_account: Stored (draftFolder " +
316            vI_account.account.defaultIdentity.draftFolder + " draftsFolderPickerMode " +
317            vI_account.account.defaultIdentity.draftsFolderPickerMode + "(" +
318            vI.preferences.getCharPref("draftFolderPickerMode") + "))\n");
319    },
320   
321    setupTemplates : function() {
322        switch (vI.preferences.getCharPref("stationeryFolderPickerMode"))
323        {
324            case "2"  :
325            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Settings of Default Account\n");
326            vI_account.account.defaultIdentity.stationeryFolder = vI_account.AccountManager.defaultAccount.defaultIdentity.stationeryFolder;
327            vI_account.account.defaultIdentity.tmplFolderPickerMode = vI_account.AccountManager.defaultAccount.defaultIdentity.tmplFolderPickerMode;
328            break;
329            case "3"  :
330            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Settings of Modified Account\n");
331            vI_account.account.defaultIdentity.stationeryFolder = vI_account._getBaseIdentity().stationeryFolder;
332            vI_account.account.defaultIdentity.tmplFolderPickerMode = vI_account._getBaseIdentity().tmplFolderPickerMode;
333            break;
334            default  :
335            vI_notificationBar.dump ("## vI_account: preparing Templates --- use Virtual Identity Settings\n");
336            vI_account.account.defaultIdentity.stationeryFolder
337                = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("stationeryFolder"));
338            vI_account.account.defaultIdentity.tmplFolderPickerMode
339                = vI.preferences.getCharPref("stationeryFolderPickerMode");
340            break;
341        }
342        vI_notificationBar.dump("## vI_account: Stored (stationeryFolder " +
343            vI_account.account.defaultIdentity.stationeryFolder + " tmplFolderPickerMode " +
344            vI_account.account.defaultIdentity.tmplFolderPickerMode + "(" +
345            vI.preferences.getCharPref("stationeryFolderPickerMode") + "))\n");
346    }
347}
Note: See TracBrowser for help on using the repository browser.