/
emailwizard.js
156 lines (130 loc) · 5.97 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
152
153
154
155
156
if (!org) var org = {};
if (!org.torbirdy) org.torbirdy = {};
if(!org.torbirdy.emailwizard) org.torbirdy.emailwizard = new function() {
var pub = {};
var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
// Check if we are running Tails. If yes, disable the manual account
// configuration wizard since Tails handles that on its own. See:
// https://tails.boum.org/todo/Return_of_Icedove__63__/#index6h2
// This is also disabled if "extensions.torbirdy.emailwizard" is true.
var disableWizard = false;
if (prefs.prefHasUserValue("vendor.name")) {
if (prefs.getCharPref("vendor.name") === "Tails") {
disableWizard = true;
}
}
if (prefs.getBoolPref("extensions.torbirdy.emailwizard")) {
disableWizard = true;
}
pub.disableAutoWizard = function() {
if (!disableWizard) {
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;
// Set default values to disable automatic email fetching.
config.incoming.loginAtStartup = false;
config.incoming.downloadOnBiff = false;
// Default the outgoing SMTP port.
config.outgoing.port = 465;
config.outgoing.hostname = "smtp.%EMAILDOMAIN%";
replaceVariables(config, realname, email, password);
config.rememberPassword = rememberPassword && !!password;
var newAccount = createAccountInBackend(config);
// Set check_new_mail to false. We can't do this through the account setup, so let's do it here.
var checkNewMail = 'mail.server.%serverkey%.check_new_mail';
var serverkey = newAccount.incomingServer.key;
var checkNewMailPref = checkNewMail.replace("%serverkey%", serverkey);
prefs.setBoolPref(checkNewMailPref, false);
// Make sure that drafts are saved to Local Folders if it is an IMAP account.
if (protocol === "imap") {
var identity = newAccount.defaultIdentity;
identity.draftFolder = "mailbox://nobody@Local%20Folders/Drafts";
}
// Do not check for new messages at startup.
var loginAtStartup = 'mail.server.%serverkey%.login_at_startup';
var loginAtStartupPref = loginAtStartup.replace("%serverkey%", serverkey);
prefs.setBoolPref(loginAtStartupPref, false);
// Do not automatically download new messages.
if (protocol === "pop3") {
var downloadOnBiff = 'mail.server.%serverkey%.download_on_biff';
var downloadOnBiffPref = downloadOnBiff.replace("%serverkey%", serverkey);
prefs.setBoolPref(downloadOnBiffPref, false);
}
// 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: newAccount.incomingServer,
selectPage: "am-server.xul" });
}
window.close();
}
else {
gEmailConfigWizard.onNext();
}
};
pub.onKeyEnter = function(event) {
var keycode = event.keyCode;
if (keycode == 13) {
if (document.getElementById("next_button").disabled === false) {
if (!disableWizard) {
pub.disableAutoWizard();
}
else {
gEmailConfigWizard.onNext();
}
}
}
};
pub.onLoad = function() {
if (disableWizard) {
document.getElementById("torbirdy-protocol-box").collapsed = true;
document.getElementById("provisioner_button").disabled = false;
document.getElementById("provisioner_button").hidden = false;
} else {
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);