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 | |
---|
25 | vI_account = { |
---|
26 | account : null, |
---|
27 | |
---|
28 | //~ Checks if there is stil another VIdentity Account and creates a new identity number |
---|
29 | getNewAccountNumber : function() |
---|
30 | { |
---|
31 | var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount) |
---|
32 | var FreeVIdentityNumber = 0 |
---|
33 | for (index = 0; index < accounts.length; index++) { |
---|
34 | var server = accounts[index].incomingServer; |
---|
35 | if (server && server.hostName == "virtualIdentity" |
---|
36 | && server.prettyName == |
---|
37 | document.getElementById("prettyName-Prefix").getAttribute("label") |
---|
38 | + FreeVIdentityNumber) |
---|
39 | FreeVIdentityNumber++ |
---|
40 | } |
---|
41 | return FreeVIdentityNumber; |
---|
42 | }, |
---|
43 | |
---|
44 | _copyBoolAttribute : function(name) { |
---|
45 | vI_account.account.defaultIdentity.setBoolAttribute(name, |
---|
46 | vI.helper.getBaseIdentity().getBoolAttribute(name)); |
---|
47 | }, |
---|
48 | |
---|
49 | _copyIntAttribute : function(name) { |
---|
50 | vI_account.account.defaultIdentity.setIntAttribute(name, |
---|
51 | vI.helper.getBaseIdentity().getIntAttribute(name)); |
---|
52 | }, |
---|
53 | |
---|
54 | _copyCharAttribute : function(name) { |
---|
55 | vI_account.account.defaultIdentity.setCharAttribute(name, |
---|
56 | vI.helper.getBaseIdentity().getCharAttribute(name)); |
---|
57 | }, |
---|
58 | |
---|
59 | _copyUnicharAttribute : function(name) { |
---|
60 | vI_account.account.defaultIdentity.setUnicharAttribute(name, |
---|
61 | vI.helper.getBaseIdentity().getUnicharAttribute(name)); |
---|
62 | }, |
---|
63 | |
---|
64 | copyPreferences : function() { |
---|
65 | if (vI.preferences.getBoolPref("copySMIMESettings")) { |
---|
66 | // SMIME settings |
---|
67 | vI_notificationBar.dump("## vI_account: copy S/MIME settings\n") |
---|
68 | vI_account._copyUnicharAttribute("signing_cert_name"); |
---|
69 | vI_account._copyUnicharAttribute("encryption_cert_name"); |
---|
70 | vI_account._copyIntAttribute("encryptionpolicy"); |
---|
71 | } |
---|
72 | if (vI.preferences.getBoolPref("copyEnigmailSettings")) { |
---|
73 | // pgp/enigmail settings |
---|
74 | vI_notificationBar.dump("## vI_account: copy PGP settings\n") |
---|
75 | vI_account._copyBoolAttribute("pgpSignEncrypted"); |
---|
76 | vI_account._copyBoolAttribute("pgpSignPlain"); |
---|
77 | vI_account._copyBoolAttribute("enablePgp"); |
---|
78 | vI_account._copyIntAttribute("pgpKeyMode"); |
---|
79 | vI_account._copyCharAttribute("pgpkeyId"); |
---|
80 | vI_account._copyIntAttribute("openPgpHeaderMode"); |
---|
81 | vI_account._copyCharAttribute("openPgpUrlName"); |
---|
82 | |
---|
83 | vI_account._copyBoolAttribute("pgpSignEncrypted"); |
---|
84 | vI_account._copyBoolAttribute("pgpSignPlain"); |
---|
85 | vI_account._copyIntAttribute("defaultEncryptionPolicy"); |
---|
86 | } |
---|
87 | if (vI.preferences.getBoolPref("copyAttachVCardSettings")) { |
---|
88 | // attach vcard |
---|
89 | vI_notificationBar.dump("## vI_account: copy VCard settings\n") |
---|
90 | vI_account._copyBoolAttribute("attachVCard"); |
---|
91 | vI_account._copyCharAttribute("escapedVCard"); |
---|
92 | } |
---|
93 | }, |
---|
94 | |
---|
95 | removeAccount : function() { |
---|
96 | if (vI_account.account) { |
---|
97 | vI_notificationBar.dump("## vI_account: Account " + vI_account.account.incomingServer.prettyName + " removed\n") |
---|
98 | vI_account.account.incomingServer.rootFolder.Delete(); |
---|
99 | gAccountManager.removeAccount(vI_account.account); |
---|
100 | vI_account.account = null; |
---|
101 | } |
---|
102 | }, |
---|
103 | |
---|
104 | createAccount : function() |
---|
105 | { |
---|
106 | if (vI_account.account) { // if the Account is still created, then leave all like it is |
---|
107 | alert("account still created, shouldn't happen"); |
---|
108 | return; |
---|
109 | } |
---|
110 | |
---|
111 | /* |
---|
112 | // the easiest way would be to get all requiered Attributes might be to duplicate the default account like this |
---|
113 | var recentAccount = gAccountManager.getAccount(vI.elements.Obj_MsgIdentity.selectedItem.getAttribute("accountkey")); |
---|
114 | vI.VIdent_Account = gAccountManager.duplicateAccount(recentAccount); |
---|
115 | // but this ends up in the following exception: |
---|
116 | // "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIMsgAccountManager.duplicateAccount]" |
---|
117 | // so I have to do this by hand ;( |
---|
118 | */ |
---|
119 | |
---|
120 | vI_account.account = gAccountManager.createAccount(); |
---|
121 | |
---|
122 | vI_account.account.addIdentity(gAccountManager.createIdentity()); |
---|
123 | |
---|
124 | var Number = vI_account.getNewAccountNumber(); |
---|
125 | |
---|
126 | vI_account.account.incomingServer = gAccountManager.createIncomingServer("user"+Number,"virtualIdentity","pop3"); |
---|
127 | vI_account.account.incomingServer.prettyName = document.getElementById("prettyName-Prefix").getAttribute("label") + Number; |
---|
128 | |
---|
129 | vI_account.copyMsgIdentityClone(); |
---|
130 | vI_account.copyPreferences(); |
---|
131 | vI_account.setupFcc(); |
---|
132 | |
---|
133 | |
---|
134 | // remove the folder created with this account - it should never be used to store mails |
---|
135 | vI_account.account.incomingServer.rootFolder.Delete(); |
---|
136 | |
---|
137 | vI_notificationBar.dump("## vI_account: New Account created " + vI_account.account.incomingServer.prettyName + "\n"); |
---|
138 | //~ confirm("## vI_account: New Account created "+server.prettyName+"\n"); |
---|
139 | }, |
---|
140 | |
---|
141 | copyMsgIdentityClone : function() { |
---|
142 | var address = vI.helper.getAddress(); |
---|
143 | vI_account.account.defaultIdentity.setUnicharAttribute("fullName", address.name); |
---|
144 | vI_account.account.defaultIdentity.setCharAttribute("useremail", address.email); |
---|
145 | |
---|
146 | if (vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem) |
---|
147 | vI_account.account.defaultIdentity.smtpServerKey |
---|
148 | = vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem.getAttribute('key'); |
---|
149 | else vI_notificationBar.dump("## vI_account: This shouldnt happen: SMTP-Server unselected.\n"); |
---|
150 | vI_notificationBar.dump("## vI_account: Stored virtualIdentity (name " |
---|
151 | + vI_account.account.defaultIdentity.fullName + " email " |
---|
152 | + vI_account.account.defaultIdentity.email + " smtp " |
---|
153 | + vI_account.account.defaultIdentity.smtpServerKey +")\n"); |
---|
154 | }, |
---|
155 | |
---|
156 | setupFcc : function() |
---|
157 | { |
---|
158 | if (vI.preferences.getBoolPref("doFcc")) { |
---|
159 | switch (vI.preferences.getCharPref("fcc_folder_picker_mode")) |
---|
160 | { |
---|
161 | case "2" : |
---|
162 | dump ("## vI_account: preparing Fcc --- use Settings of Default Account\n"); |
---|
163 | vI_account.account.defaultIdentity.doFcc = gAccountManager.defaultIdentity.doFcc; |
---|
164 | vI_account.account.defaultIdentity.fccFolder = gAccountManager.defaultAccount.defaultIdentity.fccFolder; |
---|
165 | vI_account.account.defaultIdentity.fccFolderPickerMode = gAccountManager.defaultAccount.defaultIdentity.fccFolderPickerMode; |
---|
166 | break; |
---|
167 | case "3" : |
---|
168 | dump ("## vI_account: preparing Fcc --- use Settings of Modified Account\n"); |
---|
169 | vI_account.account.defaultIdentity.doFcc = vI.helper.getBaseIdentity().doFcc; |
---|
170 | vI_account.account.defaultIdentity.fccFolder = vI.helper.getBaseIdentity().fccFolder; |
---|
171 | vI_account.account.defaultIdentity.fccFolderPickerMode = vI.helper.getBaseIdentity().fccFolderPickerMode; |
---|
172 | break; |
---|
173 | default : |
---|
174 | dump ("## vI_account: preparing Fcc --- use Virtual Identity Settings\n"); |
---|
175 | vI_account.account.defaultIdentity.doFcc |
---|
176 | = vI.preferences.getBoolPref("doFcc"); |
---|
177 | vI_account.account.defaultIdentity.fccFolder |
---|
178 | = vI.preferences.getCharPref("fcc_folder"); |
---|
179 | vI_account.account.defaultIdentity.fccFolderPickerMode |
---|
180 | = vI.preferences.getCharPref("fcc_folder_picker_mode"); |
---|
181 | break; |
---|
182 | } |
---|
183 | } |
---|
184 | else { |
---|
185 | dump ("## vI_account: dont performing Fcc\n"); |
---|
186 | vI_account.account.defaultIdentity.doFcc = false; |
---|
187 | } |
---|
188 | vI_notificationBar.dump("## vI_account: Stored (doFcc " + vI_account.account.defaultIdentity.doFcc + " fccFolder " + |
---|
189 | vI_account.account.defaultIdentity.fccFolder + " fccFolderPickerMode " + |
---|
190 | vI_account.account.defaultIdentity.fccFolderPickerMode + ")\n"); |
---|
191 | } |
---|
192 | } |
---|