You are not logged in.

#1 2024-09-26 20:22:07

maesli
Member
Registered: 2024-09-26
Posts: 7

[SOLVED] offlineimap not working with systemd

Hi,
I have setup offlineimaprc to fetch mail from my local protonmail-bridge-nogui service. When I run

offlineimap -o

everything runs as expected, without errors. I have tried to setup oneshot service with systed timer, but I get the following error:

$ systemctl --user status offlineimap-oneshot
× offlineimap-oneshot.service - Offlineimap Service (oneshot)
     Loaded: loaded (/usr/lib/systemd/user/offlineimap-oneshot.service; disabled; preset: enabled)
    Drop-In: /home/maesli/.config/systemd/user/offlineimap-oneshot.service.d
             └─service.conf
     Active: failed (Result: exit-code) since Thu 2024-09-26 21:52:56 CEST; 8s ago
 Invocation: 32a4f2f5ad0a4805b3267ad4992fb077
       Docs: man:offlineimap(1)
    Process: 1348 ExecStart=/usr/bin/offlineimap -o -c ${XDG_CONFIG_HOME}/offlineimap/config (code=exited, status=1/FAILURE)
   Main PID: 1348 (code=exited, status=1/FAILURE)
   Mem peak: 26.9M
        CPU: 545ms

Sep 26 21:52:56 gondolin offlineimap[1348]:     remoterepos.getfolders()
Sep 26 21:52:56 gondolin offlineimap[1348]:   File "/usr/lib/python3.12/site-packages/offlineimap/repository/IMAP.py", line 681, in getfolders
Sep 26 21:52:56 gondolin offlineimap[1348]:     imapobj = self.imapserver.acquireconnection()
Sep 26 21:52:56 gondolin offlineimap[1348]:               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 26 21:52:56 gondolin offlineimap[1348]:   File "/usr/lib/python3.12/site-packages/offlineimap/imapserver.py", line 683, in acquireconnection
Sep 26 21:52:56 gondolin offlineimap[1348]:     e.args[0][:35] == 'IMAP4 protocol error: socket error:':
Sep 26 21:52:56 gondolin offlineimap[1348]:     ~~~~~~~~~^^^^^
Sep 26 21:52:56 gondolin systemd[681]: offlineimap-oneshot.service: Main process exited, code=exited, status=1/FAILURE
Sep 26 21:52:56 gondolin systemd[681]: offlineimap-oneshot.service: Failed with result 'exit-code'.
Sep 26 21:52:56 gondolin systemd[681]: Failed to start Offlineimap Service (oneshot).

The same exact command when run from the terminal finishes correctly. I have tried playing with system variables in the systemd unit file, I have verified that the unit file is run as my user (not root), that $HOME variable is correctly set by systemd, but it didn't help. My next guess would be that protonmail-bridge somehow refuses the connection, but the command is run by the same user as in the terminal, so I'm just about out of ideas.

.config/offlineimap/config:

[general]
metadata = $XDG_CONFIG_HOME/offlineimap
accounts = proton
maxsyncaccounts = 1
pythonfile = $XDG_CONFIG_HOME/offlineimap/offlineimap.py
socktimeout = 60

[mbnames]
enabled = yes
filename = $XDG_CONFIG_HOME/mutt/muttrc.mailboxes
header = "mailboxes "
peritem = "+%(accountname)s/%(foldername)s"
sep = " "
footer = "\n"

[Account proton]
localrepository = proton-local
remoterepository = proton-remote
#autorefresh = 1
quick = 10

[Repository proton-local]
type = Maildir
localfolders = ~/.cache/mail/proton
sync_deletes = no
utime_from_header = yes

[Repository proton-remote]
type = IMAP
remotehost = 127.0.0.1
ssl = no
starttls = yes
remoteport = 1144
remoteuser = xxx@protonmail.com
#tls_level = tls_compat
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
holdconnectionopen = yes
sync_deletes = no
remotepasseval = get_pass("xxx")

.config/systemd/user/offlineimap-oneshot.service.d/service.conf:

[Service]
WatchdogSec=300
Environment=XDG_CONFIG_HOME=/home/maesli/.config
ExecStart=
#ExecStart=/usr/bin/echo ${XDG_CONFIG_HOME}
ExecStart=/usr/bin/offlineimap -o -c ${XDG_CONFIG_HOME}/offlineimap/config
#ExecStart=/usr/bin/offlineimap

Last edited by maesli (2024-09-26 23:03:09)

Offline

#2 2024-09-26 20:46:56

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] offlineimap not working with systemd

The exec lines are not parsed by a shell, so you cannot do variable expansion (at least not quite like that).  To test/confirm whether this is the issue, try hardcoding that path in the exec line.

EDIT: actually it seems you were already testing a similar idea: did that "echo" line produce the expected results when uncommented?

If you're open to wider work-arounds, I used to use offlineimap for awhile, but switched to mbsync which has repeatedly surprised me in how much better and easier it is than offlineimap - even though I was really happy with offlineimap while using it.

Last edited by Trilby (2024-09-26 20:49:16)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2024-09-26 22:07:19

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,805

Re: [SOLVED] offlineimap not working with systemd

https://www.freedesktop.org/software/sy … nd%20lines
The variable should™ be expanded.

Do you have internet before you log in?
Does the service work when you're online?
Do you have an encrypted $HOME?
Can you

/usr/bin/offlineimap -o -c ${XDG_CONFIG_HOME}/offlineimap/config <&-

in an interactive shell (nb. the "<&-" at the end)
If not, see eg. https://stackoverflow.com/questions/441 … unit-files

The journal likely has a more complete backtrace of the error?

Offline

#4 2024-09-26 23:01:13

maesli
Member
Registered: 2024-09-26
Posts: 7

Re: [SOLVED] offlineimap not working with systemd

I looked at journalctl:

ep 27 00:34:06 hostname systemd[662]: Starting Offlineimap Service (oneshot)...
░░ Subject: A start job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit UNIT has begun execution.
░░
░░ The job identifier is 106.
Sep 27 00:34:06 hostname offlineimap[2118]: OfflineIMAP 8.0.0
Sep 27 00:34:06 hostname offlineimap[2118]:   Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
Sep 27 00:34:06 hostname offlineimap[2118]: imaplib2 v3.06, Python v3.12.6, OpenSSL 3.3.2 3 Sep 2024
Sep 27 00:34:06 hostname offlineimap[2118]: Account sync proton:
Sep 27 00:34:06 hostname offlineimap[2118]:  *** Processing account proton
Sep 27 00:34:06 hostname offlineimap[2118]:  Establishing connection to 127.0.0.1:1144 (proton-remote)
Sep 27 00:34:07 hostname offlineimap[2133]: gpg: public key decryption failed: No secret key
Sep 27 00:34:07 hostname offlineimap[2133]: gpg: decryption failed: No secret key
Sep 27 00:34:07 hostname offlineimap[2118]:  ERROR: While attempting to sync account 'proton'
Sep 27 00:34:07 hostname offlineimap[2118]:   'int' object is not subscriptable
Sep 27 00:34:07 hostname offlineimap[2118]:  *** Finished account 'proton' in 0:00
Sep 27 00:34:07 hostname offlineimap[2118]: ERROR: Exceptions occurred during the run!
Sep 27 00:34:07 hostname offlineimap[2118]: ERROR: While attempting to sync account 'proton'
Sep 27 00:34:07 hostname offlineimap[2118]:   'int' object is not subscriptable
Sep 27 00:34:07 hostname offlineimap[2118]: Traceback:
Sep 27 00:34:07 hostname offlineimap[2118]:   File "/usr/lib/python3.12/site-packages/offlineimap/accounts.py", line 298, in syncrunner
Sep 27 00:34:07 hostname offlineimap[2118]:     self.__sync()
Sep 27 00:34:07 hostname offlineimap[2118]:   File "/usr/lib/python3.12/site-packages/offlineimap/accounts.py", line 374, in __sync
Sep 27 00:34:07 hostname offlineimap[2118]:     remoterepos.getfolders()
Sep 27 00:34:07 hostname offlineimap[2118]:   File "/usr/lib/python3.12/site-packages/offlineimap/repository/IMAP.py", line 681, in getfolders
Sep 27 00:34:07 hostname offlineimap[2118]:     imapobj = self.imapserver.acquireconnection()
Sep 27 00:34:07 hostname offlineimap[2118]:               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 27 00:34:07 hostname offlineimap[2118]:   File "/usr/lib/python3.12/site-packages/offlineimap/imapserver.py", line 683, in acquireconnection
Sep 27 00:34:07 hostname offlineimap[2118]:     e.args[0][:35] == 'IMAP4 protocol error: socket error:':
Sep 27 00:34:07 hostname offlineimap[2118]:     ~~~~~~~~~^^^^^
Sep 27 00:34:07 hostname systemd[662]: offlineimap-oneshot.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ An ExecStart= process belonging to unit UNIT has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Sep 27 00:34:07 hostname systemd[662]: offlineimap-oneshot.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit UNIT has entered the 'failed' state with result 'exit-code'.
Sep 27 00:34:07 hostname systemd[662]: Failed to start Offlineimap Service (oneshot).
░░ Subject: A start job for unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit UNIT has finished with a failure.
░░
░░ The job identifier is 106 and the job result is failed.

I noticed the gpg errors, so I added the GNUPGHOME variable to service.conf:

[Service]
WatchdogSec=300
Environment=XDG_CONFIG_HOME=/home/maesli/.config
Environment=GNUPGHOME=/home/maesli/.config/gpg
ExecStart=
#ExecStart=/usr/bin/echo ${XDG_CONFIG_HOME}
ExecStart=/usr/bin/offlineimap -o -c ${XDG_CONFIG_HOME}/offlineimap/config
#ExecStart=/usr/bin/offlineimap

And now everything works as expected

Offline

Board footer

Powered by FluxBB