
commit 6b037586f442d278214ccb85cca75946f878dc49 Author: Sukhbir Singh <sukhbir@torproject.org> Date: Thu Dec 26 01:20:09 2013 -0500 Save draft messages for IMAP accounts locally (closes #10309) --- ChangeLog | 1 + chrome/content/preferences.js | 29 +++++++++++------------ components/torbirdy.js | 51 ++++++++++++++++++++++++++++++++--------- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ec8146..3719be7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ New translations: Japanese, Malay, Russian Show the Sender header in message pane (closes #10226) + Draft messages on IMAP accounts are now saved locally (closes #10309) 0.1.2, 04 Nov 2013 New options: diff --git a/chrome/content/preferences.js b/chrome/content/preferences.js index 5ec06b8..1930f98 100644 --- a/chrome/content/preferences.js +++ b/chrome/content/preferences.js @@ -144,22 +144,19 @@ if (!org.torbirdy.prefs) org.torbirdy.prefs = new function() { var mailAccounts = []; var accounts = pub.acctMgr.accounts; - // Maintain Gecko 17+ and Gecko < 17 compatibility. - if (accounts.queryElementAt) { - for (var i = 0; i < accounts.length; i++) { - var account = accounts.queryElementAt(i, Components.interfaces.nsIMsgAccount).incomingServer; - var name = account.prettyName; - if (!(name === "Local Folders")) { - mailAccounts.push(account); - } - } - } else { - for (var i = 0; i < accounts.Count(); i++) { - var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount).incomingServer; - var name = account.prettyName; - if (!(name === "Local Folders")) { - mailAccounts.push(account); - } + // To maintain compatibility between Gecko 17+ and Gecko < 17. + var newGecko = (accounts.queryElementAt) ? true : false; + + var accountLength = newGecko ? accounts.length : accounts.Count(); + + for (var i = 0; i < accountLength; i++) { + var account = (newGecko) ? + accounts.queryElementAt(i, Components.interfaces.nsIMsgAccount).incomingServer : + accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount).incomingServer; + + var name = account.prettyName; + if (!(name === "Local Folders")) { + mailAccounts.push(account); } } return mailAccounts; diff --git a/components/torbirdy.js b/components/torbirdy.js index c9cdb78..b2dfd37 100644 --- a/components/torbirdy.js +++ b/components/torbirdy.js @@ -301,7 +301,7 @@ const TorBirdyPrefs = { // when TorBirdy is initialized that should be preserved instead. When TorBirdy // is disabled or uninstalled, these preferences are restored to their original // value. All such preferences go here. -const TorBirdyOldPrefs = [ +var TorBirdyOldPrefs = [ "network.proxy.type", "network.proxy.ssl_port", "network.proxy.ssl", @@ -492,18 +492,47 @@ TorBirdy.prototype = { // Iterate through all accounts and disable automatic checking of emails. var accounts = this.acctMgr.accounts; - // To maintain compatibility between Gecko 17+ and Gecko < 17. var allAccounts = []; - if (accounts.queryElementAt) { - for (var i = 0; i < accounts.length; i++) { - var account = accounts.queryElementAt(i, Ci.nsIMsgAccount).incomingServer; - allAccounts.push(account); - } - } else { - for (var i = 0; i < accounts.Count(); i++) { - var account = accounts.QueryElementAt(i, Ci.nsIMsgAccount).incomingServer; - allAccounts.push(account); + // To maintain compatibility between Gecko 17+ and Gecko < 17. + var newGecko = (accounts.queryElementAt) ? true : false; + + var accountLength = newGecko ? accounts.length : accounts.Count(); + + for (var i = 0; i < accountLength; i++) { + var account = (newGecko) ? + accounts.queryElementAt(i, Ci.nsIMsgAccount).incomingServer : + accounts.QueryElementAt(i, Ci.nsIMsgAccount).incomingServer; + allAccounts.push(account); + } + + // Get the locations of the Draft folder for all identities and save them. + var identities = this.acctMgr.allIdentities; + var identLength = newGecko ? identities.length : identities.Count(); + + for (var ident = 0; ident < identLength; ident++) { + var identity = (newGecko) ? + identities.queryElementAt(ident, Ci.nsIMsgIdentity) : + identities.QueryElementAt(ident, Ci.nsIMsgIdentity); + + var key = identity.key; + var restorePrefs = ["draft_folder", "drafts_folder_picker_mode"]; + + for (var r = 0; r < restorePrefs.length; r++) { + var pref = "mail.identity.%id%.".replace("%id%", key); + var prefName = pref + restorePrefs[r]; + if (this.prefs.prefHasUserValue(prefName)) { + var typePref = this.prefs.getPrefType(prefName); + if (typePref === 32) { + var currentPref = this.prefs.getCharPref(prefName); + this.prefs.setCharPref(kRestoreBranch + prefName, currentPref); + } + TorBirdyOldPrefs.push(prefName); + } } + // Now apply our setting where we set the Drafts folder to Local Folders. + // The user is free to change this as this setting is not enforced. + identity.draftFolder = "mailbox://nobody@Local%20Folders/Drafts"; + identity.draftsFolderPickerMode = 0; } for (var i = 0; i < allAccounts.length; i++) {