Open 7abbix opened 4 years ago
It's not possible to define a logfile in the configuration file. For quick sync, see : https://github.com/OfflineIMAP/offlineimap/blob/master/offlineimap.conf#L291
I think the best way to get what you want is to write a small shell script, BTW.
Hi nicolas33! Thanks for the tip! I could do a workaround on logging to capture and handle the output within calling python script.
Is it correct for config: quick=0 act the same as "/usr/bin/offlineimap -o -q" ? What may be the negative effects of constantly using only quick syncs for a long period of time? In my setup we receive on Gmail mailbox thousands of emails per day. And offlineimap sync script is supposed to be run every minute to synchronize mail, process them and delete.
I think the best way to get what you want is to write a small shell script, BTW.
It was a shell script previously, but because of human-incompatible shell script syntax, we decided to move on using python, which is much easier to scale, develop and extend. As the result python spawns a separate process to call offlineimap sync command and that needs to be whitelisted in sudoers config separately. Okay, with your suggestion I could create a separate shell script with only offlineimap + arguments wrapped inside and call that shell script inside main python script.
Also I can't seem to get "-f INBOX" working in offlineimaprc. Incoming synced mail should be put into /var/mail/alertmail/INBOX/ where are subfolders "new", "cur" "tmp".
In offlineimaprc config file I have this:
[Repository AlertsRemote] //Okay, this removes the [Gmail] prefix nametrans = lambda f: f.replace('[Gmail]/', '') if f.startswith('[Gmail]/') else f
[Repository AlertsLocal] //And this at least works folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']
However, In order to sync everything to "/var/mail/alertmail/INBOX/" I need to run offlineimap -o -f INBOX and then all the trash like trash/sent/spam/etc gets disabled and only All Mail main inbox is synced to /var/mail/alertmail/INBOX/ Without creating any subfolders.
None of examples on original site and documentation helped me with this scenario. If not "-f INBOX" specified then it always tries to create unneeded subfolders with labels, etc.
I don't want to specify every Gmail folder in folderfilter, then I want to disable. Because it is not correct to hardcode things like this. Gmail may eventually add new unneeded folders, which I don't want to maintain and hardcode in configuration. "-f INBOX" is great option to disable everything and sync only that specified folder, but is there an offlineimaprc elegant equivalent ?
Okay, with your suggestion I could create a separate shell script with only offlineimap + arguments wrapped inside and call that shell script inside main python script.
Yes. The usual approach of unix programs is to have defaults in configuration files which are superseded by CLI options. That's what we do in offlineimap so a workaround is required to avoid options tunning.
The other workaround I see for python developers is to forbid the offlineimap executable and write your own. Currently, this file calls OfflineImap().run() without arguments. Then, this calls __parse_cmd_options()
. I'm open to patches to make __parse_cmd_options()
public so that advanced users are able to call run()
with fixed options:
In offlineimap.py:
oi = OfflineImap()
options, args = oi.parse_cmd_options()
or.run(options, args)
These changes would allow to write a new executable caller with fixed options:
In your own offlineimap-fixer.py executable:
oi = OfflineImap()
options, args = oi.parse_cmd_options()
# Fix options.
options.whatever = 'FIXED_VALUE'
options.configoverride = []
options.quick = False
options.folders = ["INBOX"]
options.syslog = False
oi.run(options, args)
However, In order to sync everything to "/var/mail/alertmail/INBOX/" I need to run offlineimap -o -f INBOX and then all the trash like trash/sent/spam/etc gets disabled and only All Mail main inbox is synced to /var/mail/alertmail/INBOX/ Without creating any subfolders.
None of examples on original site and documentation helped me with this scenario. If not "-f INBOX" specified then it always tries to create unneeded subfolders with labels, etc.
I don't want to specify every Gmail folder in folderfilter, then I want to disable. Because it is not correct to hardcode things like this. Gmail may eventually add new unneeded folders, which I don't want to maintain and hardcode in configuration. "-f INBOX" is great option to disable everything and sync only that specified folder, but is there an offlineimaprc elegant equivalent ?
What about:
folderfilter = lambda foldername: foldername in ['[Gmail]/INBOX']]
?
However, In order to sync everything to "/var/mail/alertmail/INBOX/" I need to run offlineimap -o -f INBOX and then all the trash like trash/sent/spam/etc gets disabled and only All Mail main inbox is synced to /var/mail/alertmail/INBOX/ Without creating any subfolders. None of examples on original site and documentation helped me with this scenario. If not "-f INBOX" specified then it always tries to create unneeded subfolders with labels, etc. I don't want to specify every Gmail folder in folderfilter, then I want to disable. Because it is not correct to hardcode things like this. Gmail may eventually add new unneeded folders, which I don't want to maintain and hardcode in configuration. "-f INBOX" is great option to disable everything and sync only that specified folder, but is there an offlineimaprc elegant equivalent ?
What about:
folderfilter = lambda foldername: foldername in ['[Gmail]/INBOX']]
?
Hi, thanks for the tips!
I think I managed to achieve the desired configuration using the following settings:
[Repository AlertsRemote] ... nametrans = lambda f: f.replace('[Gmail]/', '') if f.startswith('[Gmail]/') else f folderfilter = lambda folder: folder in ['INBOX']
[Repository AlertsLocal]
type = Maildir
localfolders = /var/spool/mail/alerts
restoreatime = no
#sync_deletes = yes
createfolders = False
folderfilter = lambda folder: folder in ['INBOX']
In result of "/usr/bin/offlineimap --info" output I see:
Remote repository AlertsRemote: type IMAP
Folderlist:
Drafts (disabled)
[Gmail]/Drafts -> Drafts (disabled)
INBOX
Sent Mail (disabled)
[Gmail]/Sent Mail -> Sent Mail (disabled)
Spam (disabled)
[Gmail]/Spam -> Spam (disabled)
Trash (disabled)
[Gmail]/Trash -> Trash (disabled)
System (disabled)
System/AAA (disabled)
System/AAA/Discovery (disabled)
System/AAA/Heartbeat (disabled)
System/AAA/Problems (disabled)
System/BBB (disabled)
System/BBB/Discovery (disabled)
System/BBB/Heartbeat (disabled)
System/BBB/Problems (disabled)
System/CCC (disabled)
System/CCC/Discovery (disabled)
System/CCC/Heartbeat (disabled)
System/CCC/Problems (disabled)
Local repository AlertsLocal: type Maildir
folderfilter= lambda folder: folder in ['INBOX']
Folderlist:
INBOX
This looks the same, when it previously was overriden with cmd argument: /usr/bin/offlineimap -o -f INBOX --info "-f INBOX" exactly disabled everything but specified folder to sync.
General informations
offlineimap -V
): offlineimap v7.2.3, imaplib2 v2.57 (bundled), Python v2.7.5, OpenSSL 1.0.2k-fips 26 Jan 2017Configuration file offlineimaprc
pythonfile (if any)
Logs, error
Steps to reproduce the error
Well, I need to limit permission for running user that syncs email, due to ancient python 2.7 used in Offlineimap, etc. Because of Linux Visudo inability to handle spaces and command arguments properly, the only reliable way to grant such permissions is using command to offlineimap executable without any additional arguments like this: alerter ALL=(gmail) NOPASSWD: /usr/bin/offlineimap
Allowing with wildcard like this: alerter ALL=(gmail) NOPASSWD: /usr/bin/offlineimap * Is dangerous and introduces security breach, so can't be used.
However, original command that is needed to be pre-configured in .offlineimaprc is this: /usr/bin/offlineimap -o -c "/lib/gmail/.offlineimaprc" -f "INBOX" -l "/var/log/alerts/alert.log"
Okay, it is possible to pre-configure sync folder "INBOX" inside config file, but what about other options ?
logfile - ? do_only_quick_syncs - ?