-
Notifications
You must be signed in to change notification settings - Fork 20
/
emailwizard.js
151 lines (123 loc) · 5.59 KB
/
emailwizard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Components.utils.import("resource://gre/modules/Preferences.jsm");
if (!org) var org = {};
if (!org.torbirdy) org.torbirdy = {};
if(!org.torbirdy.emailwizard) org.torbirdy.emailwizard = new function() {
var pub = {};
var disableAutoConfiguration = false;
if (Preferences.get("extensions.torbirdy.emailwizard", false)) {
disableAutoConfiguration = true;
}
fixupTorbirdySettingsOnNewAccount = function(account) {
var idkey = account.defaultIdentity.key;
var serverkey = account.incomingServer.key;
var protocol = account.incomingServer.type;
var pref_spec = [
['mail.server.%serverkey%.check_new_mail', false],
['mail.server.%serverkey%.login_at_startup', false]
];
// Make sure that drafts are saved to Local Folders if it is an IMAP account.
if (protocol === "imap") {
pref_spec.push(['mail.identity.%idkey%.draft_folder',
'mailbox://nobody@Local%20Folders/Drafts']);
}
// Do not automatically download new messages in POP accounts.
if (protocol === "pop3") {
pref_spec.push(['mail.server.%serverkey%.download_on_biff', false]);
}
for each (var [pref_template, value] in pref_spec) {
var pref = pref_template.replace("%idkey%", idkey);
pref = pref.replace("%serverkey%", serverkey);
Preferences.set(pref, value);
}
}
pub.adjustAutoWizard = function() {
if (!disableAutoConfiguration) {
var realname = document.getElementById("realname").value;
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
var rememberPassword = document.getElementById("remember_password").checked;
var protocol = document.getElementById("torbirdy-protocol").value;
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var bundles = Cc["@mozilla.org/intl/stringbundle;1"]
.getService(Ci.nsIStringBundleService);
var strings = bundles.createBundle("chrome://castironthunderbirdclub/locale/torbirdy.properties");
var emailPrompt = strings.formatStringFromName("torbirdy.email.prompt", [email], 1);
var extName = strings.GetStringFromName("torbirdy.name");
prompts.alert(null, extName, emailPrompt);
var config = new AccountConfig();
config.incoming.type = protocol;
config.incoming.username = "%EMAILLOCALPART%";
config.outgoing.username = "%EMAILLOCALPART%";
if (protocol === "imap") {
config.incoming.hostname = "imap.%EMAILDOMAIN%";
config.incoming.port = 993;
}
if (protocol === "pop3") {
config.incoming.hostname = "pop.%EMAILDOMAIN%";
config.incoming.port = 995;
}
// Default to SSL for both outgoing and incoming servers.
config.incoming.socketType = 2;
config.outgoing.socketType = 2;
// Set the authentication to 'Normal' (connection is already encrypted).
config.incoming.auth = 3;
config.outgoing.auth = 3;
// Default the outgoing SMTP port.
config.outgoing.port = 465;
config.outgoing.hostname = "smtp.%EMAILDOMAIN%";
replaceVariables(config, realname, email, password);
config.rememberPassword = rememberPassword && !!password;
var new_account = createAccountInBackend(config);
fixupTorbirdySettingsOnNewAccount(new_account);
// From comm-release/mailnews/base/prefs/content/accountcreation/emailWizard.js : onAdvancedSetup().
var windowManager = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
var existingAccountManager = windowManager
.getMostRecentWindow("mailnews:accountmanager");
if (existingAccountManager) {
existingAccountManager.focus();
} else {
window.openDialog("chrome://messenger/content/AccountManager.xul",
"AccountManager", "chrome,centerscreen,modal,titlebar",
{ server: new_account.incomingServer,
selectPage: "am-server.xul" });
}
window.close();
}
else {
// From comm-release/mailnews/base/prefs/content/accountcreation/emailWizard.js : finish().
// We need somewhere to hook in, so we can access the new
// account object created through the autoconfig wizard, and
// apply Torbirdy's settings on it.
gEmailConfigWizard.finish = function() {
gEmailWizardLogger.info("creating account in backend");
var account = createAccountInBackend(this.getConcreteConfig());
fixupTorbirdySettingsOnNewAccount(account);
window.close();
}
gEmailConfigWizard.onNext();
}
};
pub.onKeyEnter = function(event) {
var keycode = event.keyCode;
if (keycode == 13) {
if (document.getElementById("next_button").disabled === false) {
pub.adjustAutoWizard();
}
}
};
pub.onLoad = function() {
if (disableAutoConfiguration) {
document.getElementById("torbirdy-protocol-box").collapsed = true;
}
document.getElementById("provisioner_button").disabled = true;
document.getElementById("provisioner_button").hidden = true;
// 0 is for POP3 (default), 1 is for IMAP. See emailwizard.xul and prefs.js.
var selectProtocol = prefs.getIntPref("extensions.torbirdy.defaultprotocol")
document.getElementById("torbirdy-protocol").selectedIndex = selectProtocol;
};
return pub;
};
window.addEventListener("keypress", org.torbirdy.emailwizard.onKeyEnter, true);
window.addEventListener("load", org.torbirdy.emailwizard.onLoad, true);