2

I am trying to autosync my mail in mutt using offlineimap via a systemd service. I am using these files and have moved them to the /etc/systemd/user folder.

However, I am storing my password via the gnome-keyring and retrieving it via secret-tool lookup user [user] domain gmail.com. This works from the command line, but the service returns the following:

user@computer:~/.dotfiles$ systemctl --user -l status offlineimap.service
● offlineimap.service - Offlineimap Service
   Loaded: loaded (/etc/systemd/user/offlineimap.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2016-06-10 10:03:43 CEST; 11s ago
  Process: 5193 ExecStart=/usr/bin/offlineimap -o -u syslog (code=exited, status=1/FAILURE)
 Main PID: 5193 (code=exited, status=1/FAILURE)

Jun 10 10:03:40 computer offlineimap[5193]: Establishing connection to imap.gmail.com:993
Jun 10 10:03:43 computer ERROR[5193]: While attempting to sync account 'MyAccount'
                                       Command 'secret-tool lookup user myaccount domain gmail.com' returned non-zero exit status 1
Jun 10 10:03:43 computer offlineimap[5193]: *** Finished account 'MyAccount' in 0:03
Jun 10 10:03:43 computer ERROR[5193]: Exceptions occurred during the run!
Jun 10 10:03:43 computer ERROR[5193]: While attempting to sync account 'MyAccount'
                                       Command 'secret-tool lookup user myaccount domain gmail.com' returned non-zero exit status 1
Jun 10 10:03:43 computer Traceback[5193]:   File "/usr/lib/python2.7/site-packages/offlineimap/accounts.py", line 263, in syncrunner
                                             self.__sync()
                                           File "/usr/lib/python2.7/site-packages/offlineimap/accounts.py", line 326, in __sync
                                             remoterepos.getfolders()
                                           File "/usr/lib/python2.7/site-packages/offlineimap/repository/IMAP.py", line 390, in getfolders
                                             imapobj = self.imapserver.acquireconnection()
                                           File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 511, in acquireconnection
                                             self.__authn_helper(imapobj)
                                           File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 411, in __authn_helper
                                             if func(imapobj):
                                           File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 350, in __authn_login
                                             self.__loginauth(imapobj)
                                           File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 203, in __loginauth
                                             imapobj.login(self.username, self.__getpassword())
                                           File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 159, in __getpassword
                                             self.password = self.repos.getpassword() or \
                                           File "/usr/lib/python2.7/site-packages/offlineimap/repository/IMAP.py", line 332, in getpassword
                                             return self.localeval.eval(passwd)
                                           File "/usr/lib/python2.7/site-packages/offlineimap/localeval.py", line 48, in eval
                                             return eval(text, names)
                                           File "<string>", line 1, in <module>
                                           File "/home/user/.mutt/offlineimap.py", line 8, in get_keychain_pass
                                             stderr=subprocess.STDOUT)
                                           File "/usr/lib64/python2.7/subprocess.py", line 573, in check_output
                                             raise CalledProcessError(retcode, cmd, output=output)
Jun 10 10:03:43 computer systemd[1075]: offlineimap.service: Main process exited, code=exited, status=1/FAILURE
Jun 10 10:03:43 computer systemd[1075]: Failed to start Offlineimap Service.
Jun 10 10:03:43 computer systemd[1075]: offlineimap.service: Unit entered failed state.
Jun 10 10:03:43 computer systemd[1075]: offlineimap.service: Failed with result 'exit-code'.

I already found out that the problem might lie in the dbus communication, but I'm not sure how to fix it. Can anyone provide an insight?

Edit:

I solved the (harmless) warning related to XOAUTH2 with the following addition to the [Repository YOUR_ACCOUNT-remote] section as suggested by this forum thread.

auth_mechanisms = LOGIN

However, the problem is unrelated but to prevent confusion, I have updated the error above accordingly.

  • I am curious whether you found a solution for this. bbs.archlinux.org/viewtopic.php?pid=1531072#p1531072 – Vishal Belsare Jan 6 '17 at 18:30
  • I haven't, unfortunately. Thanks for the link! – Ruben Jan 6 '17 at 18:34
  • I'd love if you post back here, if you either find a solution or the workaround mentioned in that link is something you get to work. I am in a similar spot, attempting to use secret-tool / gnome keyring in systemd services. – Vishal Belsare Jan 6 '17 at 18:38
  • 1
    I was struggling with a similar issue, and what I discovered was that on Ubuntu 16.04 the user session is still managed by upstart, rather than systemd. This meant that the DBUS_SESSION_BUS_ADDRESS environment variable wasn't set, and therefore the keyring couldn't access the dbus when called from a systemd unit – Felipe Jul 26 '17 at 12:00
  • Thank you both for the comments. How did you solve it Felipe? I can't test it because I use Fedora now, but maybe you can post an answer for people that have this issue too. – Ruben Aug 14 '17 at 13:24
0

One solution I can imagine, will try to test it later, is use of systemd environmental variables or systemd execution environment and let your offlineIMAP password script echo the environment variable which is the password. Your could also try to use client certificates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.