diff --git a/Changelog.rst b/Changelog.rst index 4fd26a1..129709a 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -16,6 +16,10 @@ OfflineIMAP v6.5.6 (YYYY-MM-DD) adds mechanics to change message labels (Abdó Roig-Maranges) * Allow to migrate status data across differend backends (Abdó Roig-Maranges) +* Support XDG Base Directory Specification + (if $XDG_CONFIG_HOME/offlineimap/config exists, use it as the + default configuration path; ~/.offlineimaprc is still tried after + XDG location) (GitHub#32) OfflineIMAP v6.5.5 (2013-10-07) diff --git a/README.md b/README.md index edafae7..bc839af 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,13 @@ to do is specify a directory for your folders to be in (on the localfolders line), the host name of your IMAP server (on the remotehost line), and your login name on the remote (on the remoteuser line). That's it! +If you prefer to be XDG-compatible, + http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html +then substitute the above ``~/.offlineimaprc'' with +``$XDG\_CONFIG\_HOME/offlineimap/config'' and don't forget to set +XDG\_CONFIG\_HOME properly if you want it to be different from +the default ``$HOME/.config'' for any reason. + To run OfflineIMAP, you just have to say `offlineimap` ― it will fire up, ask you for a login password if necessary, synchronize your folders, and exit. See? diff --git a/docs/MANUAL.rst b/docs/MANUAL.rst index 8a0c5a6..a5c61bd 100644 --- a/docs/MANUAL.rst +++ b/docs/MANUAL.rst @@ -63,6 +63,9 @@ set, and you can read about other features later with `offlineimap.conf`. Check out the `Use Cases`_ section for some example configurations. +If you want to be XDG-compatible, you can put your configuration file into +`$XDG_CONFIG_HOME/offlineimap/config`. + OPTIONS ======= diff --git a/docs/doc-src/FAQ.rst b/docs/doc-src/FAQ.rst index b8c2b56..29fa928 100644 --- a/docs/doc-src/FAQ.rst +++ b/docs/doc-src/FAQ.rst @@ -77,6 +77,15 @@ based in instructions submitted by Chris Walker:: That URL also has more details on making OfflineIMAP work with Windows. +Does OfflineIMAP supports XDG Base Directory specification? +----------------------------------------------------------- + +Yes. We are trying to use `$XDG_CONFIG_HOME/offlineimap/config` +as the primary configuration file, falling back to `~/.offlineimaprc` +if configuration file location was not explicitely specified at the +command line. + + Does OfflineIMAP support mbox, mh, or anything else other than Maildir? ----------------------------------------------------------------------- diff --git a/offlineimap/init.py b/offlineimap/init.py index d4c9a6d..9193bd8 100644 --- a/offlineimap/init.py +++ b/offlineimap/init.py @@ -101,9 +101,8 @@ class OfflineImap: "or to sync some accounts that you normally prefer not to.") parser.add_option("-c", dest="configfile", metavar="FILE", - default="~/.offlineimaprc", - help="Specifies a configuration file to use in lieu of " - "%default.") + default=None, + help="Specifies a configuration file to use") parser.add_option("-d", dest="debugtype", metavar="type1,[type2...]", help="Enables debugging for OfflineIMAP. This is useful " @@ -165,7 +164,19 @@ class OfflineImap: globals.set_options (options) #read in configuration file - configfilename = os.path.expanduser(options.configfile) + if not options.configfile: + # Try XDG location, then fall back to ~/.offlineimaprc + xdg_var = 'XDG_CONFIG_HOME' + if not xdg_var in os.environ or not os.environ[xdg_var]: + xdg_home = os.path.expanduser('~/.config') + else: + xdg_home = os.environ[xdg_var] + options.configfile = os.path.join(xdg_home, "offlineimap", "config") + if not os.path.exists(options.configfile): + options.configfile = os.path.expanduser('~/.offlineimaprc') + configfilename = options.configfile + else: + configfilename = os.path.expanduser(options.configfile) config = CustomConfigParser() if not os.path.exists(configfilename):