summaryrefslogtreecommitdiffstats
path: root/config/chroot_local-patches/torbirdy-0001-secure-autoconfig-compat.diff
blob: cf058039f5c931f31babb5fc6c7acf8804292176 (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
--- /usr/share/xul-ext/torbirdy/chrome/content/emailwizard.js.orig
+++ /usr/share/xul-ext/torbirdy/chrome/content/emailwizard.js
@@ -1,28 +1,46 @@
+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 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;
-    }
+  var disableAutoConfiguration = false;
+  if (Preferences.get("extensions.torbirdy.emailwizard", false)) {
+    disableAutoConfiguration = true;
   }
-  if (prefs.getBoolPref("extensions.torbirdy.emailwizard")) {
-    disableWizard = 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.disableAutoWizard = function() {
-    if (!disableWizard) {
+  pub.adjustAutoWizard = function() {
+    if (!disableAutoConfiguration) {
       var realname = document.getElementById("realname").value;
       var email = document.getElementById("email").value;
       var password = document.getElementById("password").value;
@@ -63,10 +81,6 @@ if(!org.torbirdy.emailwizard) org.torbirdy.emailwizard = new function() {
       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;
 
@@ -75,31 +89,8 @@ if(!org.torbirdy.emailwizard) org.torbirdy.emailwizard = new function() {
       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);
-      }
+      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"]
@@ -111,12 +102,23 @@ if(!org.torbirdy.emailwizard) org.torbirdy.emailwizard = new function() {
       } else {
         window.openDialog("chrome://messenger/content/AccountManager.xul",
                           "AccountManager", "chrome,centerscreen,modal,titlebar",
-                          { server: newAccount.incomingServer,
+                          { 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();
     }
   };
@@ -125,25 +127,17 @@ if(!org.torbirdy.emailwizard) org.torbirdy.emailwizard = new function() {
     var keycode = event.keyCode;
     if (keycode == 13) {
       if (document.getElementById("next_button").disabled === false) {
-        if (!disableWizard) {
-          pub.disableAutoWizard();
-        }
-        else {
-          gEmailConfigWizard.onNext();
-        }
+        pub.adjustAutoWizard();
       }
     }
   };
 
   pub.onLoad = function() {
-    if (disableWizard) {
+    if (disableAutoConfiguration) {
       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;
     }
+    document.getElementById("provisioner_button").disabled = true;
+    document.getElementById("provisioner_button").hidden = true;
   };
 
   return pub;
--- /usr/share/xul-ext/torbirdy/chrome/content/emailwizard.xul.orig
+++ /usr/share/xul-ext/torbirdy/chrome/content/emailwizard.xul
@@ -9,7 +9,7 @@
   </stringbundleset>
 
   <button id="next_button"
-      oncommand="org.torbirdy.emailwizard.disableAutoWizard();" />
+      oncommand="org.torbirdy.emailwizard.adjustAutoWizard();" />
 
   <vbox id="mastervbox" flex="1">
     <groupbox id="torbirdy-protocol-box" class="indent" insertafter="initialSettings">
--- /usr/share/xul-ext/torbirdy/chrome/content/preferences.js.orig
+++ /usr/share/xul-ext/torbirdy/chrome/content/preferences.js
@@ -37,36 +37,20 @@ if (!org.torbirdy.prefs) org.torbirdy.prefs = new function() {
   };
 
   pub.setEnigmailPrefs = function(anonService) {
+    var opts = "";
     if (pub.prefs.getBoolPref("extensions.torbirdy.enigmail.throwkeyid")) {
-      if (anonService === "tor") {
-        return "--no-emit-version " +
-               "--no-comments " +
-               "--throw-keyids " +
-               "--display-charset utf-8 " +
-               "--keyserver-options no-auto-key-retrieve,no-try-dns-srv,http-proxy=http://127.0.0.1:8118";
-      }
-      if (anonService === "jondo") {
-        return "--no-emit-version " +
-               "--no-comments " +
-               "--throw-keyids " +
-               "--display-charset utf-8 " +
-               "--keyserver-options no-auto-key-retrieve,no-try-dns-srv,http-proxy=http://127.0.0.1:4001";
-      }
-    }
-    else {
-      if (anonService === "tor") {
-        return "--no-emit-version " +
-               "--no-comments " +
-               "--display-charset utf-8 " +
-               "--keyserver-options no-auto-key-retrieve,no-try-dns-srv,http-proxy=http://127.0.0.1:8118";
-      }
-      if (anonService === "jondo") {
-        return "--no-emit-version " +
-               "--no-comments " +
-               "--display-charset utf-8 " +
-               "--keyserver-options no-auto-key-retrieve,no-try-dns-srv,http-proxy=http://127.0.0.1:4001";
-      }
+      opts += "--throw-keyids ";
     }
+    var proxy = "socks5h://127.0.0.1:9050";
+    if (anonService === "jondo") {
+      proxy = "http://127.0.0.1:4001";
+    }
+    return opts +
+           "--no-emit-version " +
+           "--no-comments " +
+           "--display-charset utf-8 " +
+           "--keyserver-options no-auto-key-retrieve,no-try-dns-srv,http-proxy=" +
+           proxy;
   };
 
   pub.updateKeyserver = function(anonService) {
--- /usr/share/xul-ext/torbirdy/components/torbirdy.js.orig
+++ /usr/share/xul-ext/torbirdy/components/torbirdy.js
@@ -181,6 +181,14 @@ const TorBirdyPrefs = {
   "mail.inline_attachments": false,
   // Do not IDLE (disable push mail).
   "mail.server.default.use_idle": false,
+  // Thunderbird's autoconfig wizard is designed to enable an initial
+  // mail fetch (by setting login_at_start) for the first account it
+  // creates (which will become the "default" account, see
+  // msgMail3PaneWindow.js for details) which side-steps the settings
+  // we apply in fixupTorbirdySettingsOnNewAccount(). Hence, fool
+  // Thunderbird to think that this initial mail fetch has already
+  // been done so we get the settings we want.
+  "mail.startup.enabledMailCheckOnce": true,
 
   /*
     Browser
@@ -215,7 +223,7 @@ const TorBirdyPrefs = {
                                               // We want to force UTF-8 everywhere
                                               "--display-charset utf-8 " +
                                               // We want to ensure that Enigmail is proxy aware even when it runs gpg in a shell
-                                              "--keyserver-options http-proxy=http://127.0.0.1:8118 ",
+                                              "--keyserver-options http-proxy=socks5h://127.0.0.1:9050 ",
                                             
   // The default key server should be a hidden service and this is the only known one (it's part of the normal SKS network)
   "extensions.enigmail.keyserver": "hkp://qdigse2yzvuglcix.onion",