!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Mail Code.
16 *
17 * The Initial Developer of the Original Code is
18 * David Bienvenu.
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Scott MacGregor <mscott@mozilla.org>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 var gIdentity = null; // the identity we are editing (may be null for a new identity)
40 var gAccount = null; // the account the identity is (or will be) associated with
41
42 const nsIFilePicker = Components.interfaces.nsIFilePicker;
43
onLoadIdentityProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
44 function onLoadIdentityProperties()
45 {
46 // extract the account
47 gIdentity = window.arguments[0].identity;
48 gAccount = window.arguments[0].account;
49
50 initIdentityValues(gIdentity);
51 initCopiesAndFolder(gIdentity);
52 initCompositionAndAddressing(gIdentity);
53 loadSMTPServerList();
54
55 // the multiple identities editor isn't an account wizard panel so we have to do this ourselves:
56 document.getElementById('identity.smtpServerKey').value = gIdentity ? gIdentity.smtpServerKey
57 : gAccount.defaultIdentity.smtpServerKey;
58 }
59
60 // based on the values of gIdentity, initialize the identity fields we expose to the user
initIdentityValues
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
61 function initIdentityValues(identity)
62 {
63 if (identity)
64 {
65 document.getElementById('identity.fullName').value = identity.fullName;
66 document.getElementById('identity.email').value = identity.email;
67 document.getElementById('identity.replyTo').value = identity.replyTo;
68 document.getElementById('identity.organization').value = identity.organization;
69 document.getElementById('identity.attachSignature').checked = identity.attachSignature;
70
71 if (identity.signature)
72 document.getElementById('identity.signature').value = identity.signature.path;
73
74 document.getElementById('identity.attachVCard').checked = identity.attachVCard;
75 document.getElementById('identity.escapedVCard').value = identity.escapedVCard;
76 }
77
78 setupSignatureItems();
79 }
80
initCopiesAndFolder
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
81 function initCopiesAndFolder(identity)
82 {
83 // if we are editing an existing identity, use it...otherwise copy our values from the default identity
84 var copiesAndFoldersIdentity = identity ? identity : gAccount.defaultIdentity;
85
86 document.getElementById('identity.fccFolder').value = copiesAndFoldersIdentity.fccFolder;
87 document.getElementById('identity.draftFolder').value = copiesAndFoldersIdentity.draftFolder;
88 document.getElementById('identity.stationeryFolder').value = copiesAndFoldersIdentity.stationeryFolder;
89
90 document.getElementById('identity.fccFolderPickerMode').value = copiesAndFoldersIdentity.fccFolderPickerMode ? copiesAndFoldersIdentity.fccFolderPickerMode : 0;
91 document.getElementById('identity.draftsFolderPickerMode').value = copiesAndFoldersIdentity.draftsFolderPickerMode ? copiesAndFoldersIdentity.draftsFolderPickerMode : 0;
92 document.getElementById('identity.tmplFolderPickerMode').value = copiesAndFoldersIdentity.tmplFolderPickerMode ? copiesAndFoldersIdentity.tmplFolderPickerMode : 0;
93
94 document.getElementById('identity.doBcc').checked = copiesAndFoldersIdentity.doBcc;
95 document.getElementById('identity.doBccList').value = copiesAndFoldersIdentity.doBccList;
96 document.getElementById('identity.doFcc').checked = copiesAndFoldersIdentity.doFcc;
97 document.getElementById('identity.fccReplyFollowsParent').checked = copiesAndFoldersIdentity.fccReplyFollowsParent;
98 document.getElementById('identity.showSaveMsgDlg').checked = copiesAndFoldersIdentity.showSaveMsgDlg;
99 onInitCopiesAndFolders(); // am-copies.js method
100 }
101
initCompositionAndAddressing
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
102 function initCompositionAndAddressing(identity)
103 {
104 createDirectoriesList();
105
106 // if we are editing an existing identity, use it...otherwise copy our values from the default identity
107 var addressingIdentity = identity ? identity : gAccount.defaultIdentity;
108
109 document.getElementById('identity.directoryServer').value = addressingIdentity.directoryServer;
110 document.getElementById('identity.overrideGlobalPref').value = addressingIdentity.overrideGlobalPref;
111 document.getElementById('identity.composeHtml').checked = addressingIdentity.composeHtml;
112 document.getElementById('identity.autoQuote').checked = addressingIdentity.autoQuote;
113 document.getElementById('identity.replyOnTop').value = addressingIdentity.replyOnTop;
114 document.getElementById('identity.sig_bottom').value = addressingIdentity.sigBottom;
115
116 onInitCompositionAndAddressing(); // am-addressing.js method
117 }
118
onOk
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
119 function onOk()
120 {
121 if (!validEmailAddress())
122 return false;
123
124 // if we are adding a new identity, create an identity, set the fields and add it to the
125 // account.
126 if (!gIdentity)
127 {
128 // ask the account manager to create a new identity for us
129 var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"]
130 .getService(Components.interfaces.nsIMsgAccountManager);
131 gIdentity = accountManager.createIdentity();
132
133 // copy in the default identity settings so we inherit lots of stuff like the defaul drafts folder, etc.
134 gIdentity.copy(gAccount.defaultIdentity);
135
136 // assume the identity is valid by default?
137 gIdentity.valid = true;
138
139 // add the identity to the account
140 gAccount.addIdentity(gIdentity);
141
142 // now fall through to saveFields which will save our new values
143 }
144
145 // if we are modifying an existing identity, save the fields
146 saveIdentitySettings(gIdentity);
147 saveCopiesAndFolderSettings(gIdentity);
148 saveAddressingAndCompositionSettings(gIdentity);
149
150 window.arguments[0].result = true;
151
152 return true;
153 }
154
155 // returns false and prompts the user if
156 // the identity does not have an email address
validEmailAddress
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
157 function validEmailAddress()
158 {
159 var emailAddress = document.getElementById('identity.email').value;
160
161 // quickly test for an @ sign to test for an email address. We don't have
162 // to be anymore precise than that.
163 if (emailAddress.lastIndexOf("@") < 0)
164 {
165 // alert user about an invalid email address
166
167 var prefBundle = document.getElementById("bundle_prefs");
168
169 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
170 .getService(Components.interfaces.nsIPromptService);
171 promptService.alert(window, prefBundle.getString("identity-edit-req-title"),
172 prefBundle.getString("identity-edit-req"));
173 return false;
174 }
175
176 return true;
177 }
178
saveIdentitySettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
179 function saveIdentitySettings(identity)
180 {
181 if (identity)
182 {
183 identity.fullName = document.getElementById('identity.fullName').value;
184 identity.email = document.getElementById('identity.email').value;
185 identity.replyTo = document.getElementById('identity.replyTo').value;
186 identity.organization = document.getElementById('identity.organization').value;
187 identity.attachSignature = document.getElementById('identity.attachSignature').checked;
188
189 identity.attachVCard = document.getElementById('identity.attachVCard').checked;
190 identity.escapedVCard = document.getElementById('identity.escapedVCard').value;
191 identity.smtpServerKey = document.getElementById('identity.smtpServerKey').value;
192
193 var attachSignaturePath = document.getElementById('identity.signature').value;
194 identity.signature = null; // this is important so we don't accidentally inherit the default
195
196 if (attachSignaturePath)
197 {
198 // convert signature path back into a nsIFile
199 var sfile = Components.classes["@mozilla.org/file/local;1"]
200 .createInstance(Components.interfaces.nsILocalFile);
201 sfile.initWithPath(attachSignaturePath);
202 if (sfile.exists())
203 identity.signature = sfile;
204 }
205 }
206 }
207
saveCopiesAndFolderSettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
208 function saveCopiesAndFolderSettings(identity)
209 {
210 onSaveCopiesAndFolders(); // am-copies.js routine
211
212 identity.fccFolder = document.getElementById('identity.fccFolder').value;
213 identity.draftFolder = document.getElementById('identity.draftFolder').value;
214 identity.stationeryFolder = document.getElementById('identity.stationeryFolder').value;
215 identity.fccFolderPickerMode = document.getElementById('identity.fccFolderPickerMode').value;
216 identity.draftsFolderPickerMode = document.getElementById('identity.draftsFolderPickerMode').value;
217 identity.tmplFolderPickerMode = document.getElementById('identity.tmplFolderPickerMode').value;
218 identity.doBcc = document.getElementById('identity.doBcc').checked;
219 identity.doBccList = document.getElementById('identity.doBccList').value;
220 identity.doFcc = document.getElementById('identity.doFcc').checked;
221 identity.fccReplyFollowsParent = document.getElementById('identity.fccReplyFollowsParent').checked;
222 identity.showSaveMsgDlg = document.getElementById('identity.showSaveMsgDlg').checked;
223 }
224
saveAddressingAndCompositionSettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
225 function saveAddressingAndCompositionSettings(identity)
226 {
227 onSaveCompositionAndAddressing(); // am-addressing.js routine
228
229 identity.directoryServer = document.getElementById('identity.directoryServer').value;
230 identity.overrideGlobalPref = document.getElementById('identity.overrideGlobalPref').value;
231 identity.composeHtml = document.getElementById('identity.composeHtml').checked;
232 identity.autoQuote = document.getElementById('identity.autoQuote').checked;
233 identity.replyOnTop = document.getElementById('identity.replyOnTop').value;
234 identity.sigBottom = document.getElementById('identity.sig_bottom').value == 'true';
235 }
236
selectFile
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
237 function selectFile()
238 {
239 var fp = Components.classes["@mozilla.org/filepicker;1"]
240 .createInstance(nsIFilePicker);
241
242 var prefBundle = document.getElementById("bundle_prefs");
243 var title = prefBundle.getString("choosefile");
244 fp.init(window, title, nsIFilePicker.modeOpen);
245 fp.appendFilters(nsIFilePicker.filterAll);
246
247 // Get current signature folder, if there is one.
248 // We can set that to be the initial folder so that users
249 // can maintain their signatures better.
250 var sigFolder = GetSigFolder();
251 if (sigFolder)
252 fp.displayDirectory = sigFolder;
253
254 var ret = fp.show();
255 if (ret == nsIFilePicker.returnOK) {
256 var folderField = document.getElementById("identity.signature");
257 folderField.value = fp.file.path;
258 }
259 }
260
GetSigFolder
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
261 function GetSigFolder()
262 {
263 var sigFolder = null;
264 try
265 {
266 var account = parent.getCurrentAccount();
267 var identity = account.defaultIdentity;
268 var signatureFile = identity.signature;
269
270 if (signatureFile)
271 {
272 signatureFile = signatureFile.QueryInterface( Components.interfaces.nsILocalFile );
273 sigFolder = signatureFile.parent;
274
275 if (!sigFolder.exists())
276 sigFolder = null;
277 }
278 }
279 catch (ex) {
280 dump("failed to get signature folder..\n");
281 }
282 return sigFolder;
283 }
284
285 // If a signature is need to be attached, the associated items which
286 // displays the absolute path to the signature (in a textbox) and the way
287 // to select a new signature file (a button) are enabled. Otherwise, they
288 // are disabled. Check to see if the attachSignature is locked to block
289 // broadcasting events.
setupSignatureItems
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
290 function setupSignatureItems()
291 {
292 var signature = document.getElementById("identity.signature");
293 var browse = document.getElementById("identity.sigbrowsebutton");
294 var attachSignature = document.getElementById("identity.attachSignature");
295 var checked = attachSignature.checked;
296
297 if (checked && !getAccountValueIsLocked(signature))
298 signature.removeAttribute("disabled");
299 else
300 signature.setAttribute("disabled", "true");
301
302 if (checked && !getAccountValueIsLocked(browse))
303 browse.removeAttribute("disabled");
304 else
305 browse.setAttribute("disabled", "true");
306 }
307
editVCardCallback
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
308 function editVCardCallback(escapedVCardStr)
309 {
310 var escapedVCard = document.getElementById("identity.escapedVCard");
311 escapedVCard.value = escapedVCardStr;
312 }
313
editVCard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
314 function editVCard()
315 {
316 var escapedVCard = document.getElementById("identity.escapedVCard");
317
318 // read vCard hidden value from UI
319 window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",
320 "",
321 "chrome,resizable=no,titlebar,modal",
322 {escapedVCardStr:escapedVCard.value, okCallback:editVCardCallback,
323 titleProperty:"editVCardTitle", hideABPicker:true});
324 }
325
getAccountForFolderPickerState
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
326 function getAccountForFolderPickerState()
327 {
328 return gAccount;
329 }
330
331 // when the identity panel is loaded, the smtp-list is created
332 // and the in prefs.js configured smtp is activated
loadSMTPServerList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
333 function loadSMTPServerList()
334 {
335 var smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"].getService(Components.interfaces.nsISmtpService);
336 fillSmtpServers(document.getElementById('identity.smtpServerKey'), smtpService.smtpServers, smtpService.defaultServer);
337 }
338
fillSmtpServers
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
339 function fillSmtpServers(smtpServerList, servers, defaultServer)
340 {
341 if (!smtpServerList || !servers)
342 return;
343
344 var smtpPopup = document.getElementById('smtpPopup');
345 while (smtpPopup.lastChild.nodeName != "menuseparator")
346 smtpPopup.removeChild(smtpPopup.lastChild);
347
348 while (servers.hasMoreElements())
349 {
350 var server = servers.getNext();
351
352 if (server instanceof Components.interfaces.nsISmtpServer &&
353 !server.redirectorType)
354 {
355 var serverName = "";
356 if (server.description)
357 serverName = server.description + ' - ';
358 else if (server.username)
359 serverName = server.username + ' - ';
360 serverName += server.hostname;
361
362 if (defaultServer.key == server.key)
363 serverName += " " + document.getElementById("bundle_messenger").getString("defaultServerTag");
364
365 smtpServerList.appendItem(serverName, server.key);
366 }
367 }
368 }