Hello, is it possible to switch offline/online state programmatically from extension? Documentation is very limited and I can't find answer there.
For me, it would be even possible to use some kind of automation and switch offline status from outside Thunderbird. But it seems that extension is correct way to do it.
Thunderbird - go offline programatically
-
- Posts: 6432
- Joined: February 3rd, 2009, 6:29 pm
Re: Thunderbird - go offline programatically
You could create a command line handler with an extension.
Usage:
thunderbird.exe -offline
ThunderbirdPortable.exe -offline
Instructions:
* create tweaks.zip file (contains install.rdf, chrome.manifest, commandline.js)
* rename tweaks.zip file to tweaks.xpi
* install tweaks.xpi file
Source:
* install.rdf
* chrome.manifest
* commandline.js
Thunderbird 45.3.0
Windows 7 SP1 32-bit
Usage:
thunderbird.exe -offline
ThunderbirdPortable.exe -offline
Instructions:
* create tweaks.zip file (contains install.rdf, chrome.manifest, commandline.js)
* rename tweaks.zip file to tweaks.xpi
* install tweaks.xpi file
Source:
* install.rdf
Code: Select all
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>tweaks@example.com</em:id>
<em:type>2</em:type>
<em:unpack>true</em:unpack>
<em:name>Tweaks</em:name>
<em:version>1.0</em:version>
<em:creator>morat</em:creator>
<em:description>Personalize Thunderbird.</em:description>
<em:homepageURL>http://forums.mozillazine.org/viewtopic.php?f=19&t=3021875</em:homepageURL>
<!-- Thunderbird -->
<em:targetApplication>
<Description>
<em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
<em:minVersion>38.0</em:minVersion>
<em:maxVersion>99.0</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
Code: Select all
content tweaks .
locale tweaks en-US .
skin tweaks classic/1.0 .
component {3550f703-e582-4d05-9a08-453d09bdfdc6} commandline.js
contract @mozilla.org/commandlinehandler/general-startup;1?type=tweaks {3550f703-e582-4d05-9a08-453d09bdfdc6}
category command-line-handler m-tweaks @mozilla.org/commandlinehandler/general-startup;1?type=tweaks
Code: Select all
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
function TweaksCommandLineHandler() {}
TweaksCommandLineHandler.prototype = {
classID: Components.ID("{3550f703-e582-4d05-9a08-453d09bdfdc6}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
handle: function (commandLine) {
if (commandLine.handleFlag("offline", false)) {
if (commandLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
// toggle the offline status
// preference offline.download.download_messages
// 0: ask (default), 1: always download, 2: never download
var win = Services.wm.getMostRecentWindow("mail:3pane");
win.MailOfflineMgr.toggleOfflineStatus();
}
commandLine.preventDefault = true;
}
},
helpInfo: " -offline Toggle offline status.\n",
};
var NSGetFactory = XPCOMUtils.generateNSGetFactory([TweaksCommandLineHandler]);
Windows 7 SP1 32-bit
-
- Posts: 3
- Joined: September 1st, 2016, 12:09 am
Re: Thunderbird - go offline programatically
Wow, that was EXACTLY what I wanted, neatly packed as a present Thank you very much! Can some info about Services.wm.getMostRecentWindow and win.MailOfflineMgr.toggleOfflineStatus() be found in documentation? Maybe I will have to do some addons, and these things are just what I could not find.
-
- Posts: 6432
- Joined: February 3rd, 2009, 6:29 pm
Re: Thunderbird - go offline programatically
You can use the DOM Inspector extension to find the command.
File > Inspect Chrome Document > chrome://messenger/content/messenger.xul
Edit > Find Nodes > Search By Attribute
Attribute: label
Value: Work Offline
http://dxr.mozilla.org/comm-esr45/sourc ... senger.dtd
http://dxr.mozilla.org/comm-esr45/sourc ... verlay.xul
Finding already opened windows
http://developer.mozilla.org/en-US/docs ... ed_windows
http://developer.mozilla.org/en-US/docs ... ntWindow()
File > Inspect Chrome Document > chrome://messenger/content/messenger.xul
Edit > Find Nodes > Search By Attribute
Attribute: label
Value: Work Offline
Code: Select all
<!ENTITY offlineGoOfflineCmd.label "Work Offline">
Code: Select all
<menuitem id="goOfflineMenuItem"
type="checkbox"
label="&offlineGoOfflineCmd.label;"
accesskey="&offlineGoOfflineCmd.accesskey;"
oncommand="MailOfflineMgr.toggleOfflineStatus();"/>
Finding already opened windows
http://developer.mozilla.org/en-US/docs ... ed_windows
http://developer.mozilla.org/en-US/docs ... ntWindow()
-
- Posts: 3
- Joined: September 1st, 2016, 12:09 am
Re: Thunderbird - go offline programatically
I will have to study it more, but I'm begining to understand. Thanks!
-
- Posts: 6432
- Joined: February 3rd, 2009, 6:29 pm
Re: Thunderbird - go offline programatically
You're welcome.