You are not logged in.

#1 2009-09-04 13:06:19

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

[SOLVED] OfflineIMAP seems to have a syntax error in its code

Hi everyone,

I'm trying to setup Mutt using the great wiki http://wiki.archlinux.org/index.php/Mutt but when I'm done with configuring OfflineIMAP and try to run it, this happens:

Traceback (most recent call last):
  File "/usr/bin/offlineimap", line 21, in <module>
    init.startup('6.2.0')
  File "/usr/lib/python2.6/site-packages/offlineimap/init.py", line 94, in startup
    ui = offlineimap.ui.detector.findUI(config, options.get('-u'))
  File "/usr/lib/python2.6/site-packages/offlineimap/ui/detector.py", line 40, in findUI
    uimod = getUImod(uistr, config.getlocaleval(), namespace)
  File "/usr/lib/python2.6/site-packages/offlineimap/ui/detector.py", line 50, in getUImod
    uimod = localeval.eval(uistr, namespace)
  File "/usr/lib/python2.6/site-packages/offlineimap/localeval.py", line 45, in eval
    return eval(text, names)
  File "<string>", line 2
    background-processes:
             ^
SyntaxError: invalid syntax

I guess there is a syntax error in OfflineIMAP's code but don't know python so I can't find and correct it. I thought of filling a bug report but since it is down, I can't.
Is there an easy fix for this problem or not ?

Thanks for your time !

Edit: Marked as solved.

Last edited by yms (2009-09-04 17:54:17)


Sorry for any English mistakes, I am not a native speaker.

Offline

#2 2009-09-04 13:12:39

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

a syntax error in offlineimap would _not_ surprise me.  however, i use it with mutt (and even multiple imap accounts) and it's working fine.  can i see your .offlineimaprc?  maybe you didn't specify a ui?

Offline

#3 2009-09-04 13:19:38

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

Thanks for the quick reply ;-)

Here is my offlineimaprc


[general]
# change to whatever you want:
accounts = GMail 

# Gives you a nice blinky output on the console so you know what's happening:
ui = Curses.Blinkenlights 

# If uncommented, this would show nothing at all. Great for cronjobs or
  background-processes:
# ui = Noninteractive.Quiet 

[Account myaccount]
# Profile-Name for the local Mails for a given Account
localrepository = localrep 

# Profile-Name for the remote Mails for a given Account
remoterepository = remoterep 

# fetches your mails every 5 Minutes
autorefresh = 5 

[Repository localrep]
# Way of storing Mails locally. Only Maildir is currently supported:
type = Maildir 

# Place where the synced Mails should be:
localfolders = ~/personal/mail 

[Repository remoterep]
# Type of remote Mailbox. Only IMAP is supported right now:
type = IMAP 

# Where to connect:
remotehost = imap.gmail.com 

# Whether to use SSL or not:
ssl = yes 

# Would specify a port if uncommented. This way, it just tries to use a
  default-port:
# remoteport = 993 

# Specify login-name:
remoteuser = gmail.account

# Specify login-password (there are other/safer options for storing passwords
  for use by OfflineIMAP,
# see the OfflineIMAP manual. Make sure that ~/.offlineimaprc is readable only
  by you, if you 
# specify your password here!): 
remotepass = mysupersecurepasswordyoucannotsee

The only thing I changed before posting is my login and password of course (but maybe it is important that I wrote 'my.account' and not 'my.account@gmail.com'

Are you sure you use the latest version of offlineimap ? If it is indeed a syntax error, an earlier version would certainly be correct.

Thanks.


Sorry for any English mistakes, I am not a native speaker.

Offline

#4 2009-09-04 13:26:17

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

um, man offlineimap didn't find "background-processes" and considering that's what the syntax error points too...

dunno where you got it, but i'd take it out.  just use

offlineimap -u Noninteractive.Quiet &>/dev/null

if you don't want to see any output at all.

/edit: i'm on 6.2.0-1, whatever's in the repos.

/edit2: oh HAHA, reread our wiki... carefully.  you seem to have put a rogue newline in there smile (well a few actually, towards the end there).

i should really update our wiki too, offlineimap has a sweet repo type "Gmail" now, which just needs user/pass for setup.  please check out my configs if you'd like to see my gmail/offlineimap/msmtp/mutt setup.

Last edited by brisbin33 (2009-09-04 13:32:39)

Offline

#5 2009-09-04 13:50:09

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

We have the same version. That can not be the issue.

I'm currently running what you suggested but it's been runnning for several minutes and it does not seem to do much (the mail directory is still empty)

What do you mean by "rogue newlines" ? If you are refering to:

Edit according to your special needs, but take care that comments are placed on their own separate line: placing a comment after an option/value on the same line will cause errors!

then everything is fine because I just copied the example config file and all comments are on separate lines. The file does not end with a newline character either (I tried with and without)

(And thanks, I'll check your dotfiles)

Edit:

offlineimap -u Noninteractive.Quiet
gives me:

Thread 'Account sync GMail' terminated with exception:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/offlineimap/threadutil.py", line 149, in run
    Thread.run(self)
  File "/usr/lib/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.6/site-packages/offlineimap/accounts.py", line 174, in syncrunner
    self.remoterepos = offlineimap.repository.Base.LoadRepository(self.getconf('remoterepository'), self, 'remote')
  File "/usr/lib/python2.6/site-packages/offlineimap/repository/Base.py", line 37, in LoadRepository
    return typemap[repostype](name, account)
  File "/usr/lib/python2.6/site-packages/offlineimap/repository/IMAP.py", line 30, in __init__
    self.imapserver = imapserver.ConfigedIMAPServer(self)
  File "/usr/lib/python2.6/site-packages/offlineimap/imapserver.py", line 405, in __init__
    ssl = self.repos.getssl()
  File "/usr/lib/python2.6/site-packages/offlineimap/repository/IMAP.py", line 134, in getssl
    return self.getconfboolean('ssl', 0)
  File "/usr/lib/python2.6/site-packages/offlineimap/CustomConfig.py", line 93, in getconfboolean
    self.getconfig().getboolean)
  File "/usr/lib/python2.6/site-packages/offlineimap/CustomConfig.py", line 81, in _confighelper_runner
    return apply(defaultfunc, [self.getsection(), option, default])
  File "/usr/lib/python2.6/site-packages/offlineimap/CustomConfig.py", line 46, in getdefaultboolean
    kwargs)
  File "/usr/lib/python2.6/ConfigParser.py", line 351, in getboolean
    raise ValueError, 'Not a boolean: %s' % v
ValueError: Not a boolean: yes
default-port:


No debug messages were logged for Account sync GMail.

Last edited by yms (2009-09-04 14:10:55)


Sorry for any English mistakes, I am not a native speaker.

Offline

#6 2009-09-04 14:35:53

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

ok, let's clarify now.  is the forum adding newlines or is it your text editor adding newlines.  here is what i mean:

this portion of what you posted:

# Would specify a port if uncommented. This way, it just tries to use a
  default-port:
# remoteport = 993 

# Specify login-name:
remoteuser = gmail.account

# Specify login-password (there are other/safer options for storing passwords
  for use by OfflineIMAP,
# see the OfflineIMAP manual. Make sure that ~/.offlineimaprc is readable only
  by you, if you 
# specify your password here!): 
remotepass = mysupersecurepasswordyoucannotsee

is doomed for failure.  it _must_ be like this (as it is in the wiki):

# Would specify a port if uncommented. This way, it just tries to use a default-port:
# remoteport = 993 

# Specify login-name:
remoteuser = gmail.account

# Specify login-password (there are other/safer options for storing passwordsfor use by OfflineIMAP,
# see the OfflineIMAP manual. Make sure that ~/.offlineimaprc is readable only by you, if you 
# specify your password here!): 
remotepass = mysupersecurepasswordyoucannotsee

see how you had those 'rogue newlines' into the comments? offlineimap thinks your passing ' default port' and ' for use by OfflineIMAP,' as config options.

be ware the copy paste, it'll bite you.

Offline

#7 2009-09-04 16:08:56

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

Oh I did not notice. It's such a stupid mistake. It works perfectly now. I can go on with the wiki.

I have one more question though (I did not manage to find any clear answer to that) about the 'autorefresh' and 'quick' options.

I assume/hope that offlineimap does not download ALL of my mails every time it runs. So when it does its 'autorefresh' thing it only downloads new mails. But then, I do not understand what the 'quick' option is for...

Another thing is that for instance autorefresh=5 means that offlineimap should sync every 5 minutes so I guess there is a daemon I have to add somewhere in rc.conf but I can not find any documentation on such a thing. Another way to sync when needed would be to use cron but then the autorefresh option is useless.

Can you/someone explain how this works ?

Anyway thanks for your help, I really appreciate it ;-)


Sorry for any English mistakes, I am not a native speaker.

Offline

#8 2009-09-04 16:43:23

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

Sure,

first, offlineimap is a sync utility.  i.e. it will two-way-sync the IMAP source with your Maildir, only downloading changes, not your whole mailbox.  if you have autorefresh/quick options specified, then offlineimap will just never quit once it's started.  this can be overridden with the -o option (run only once). 

it's really up to you how to start it, .xinitrc, /etc/rc.local, or write your own /etc/rc.d/offlineimap daemon.  (careful though, you need to use su to ensure it's started as you and not root).

i do agree though, that the autorefresh and quick options are a bit counter intuitive:

autorefresh = how many minutes between syncing the IMAP source with the Maildir

quick = number of "quick" syncs to do before doing a "full" sync, where a "quick" sync only checks for new or deleted mails and does not update anything else (read / unread flags, mod times, i dunno), and "full" obviously updates _everything_.

so: autorefresh = 10 and quick = 5 means you'll quick-sync every ten minutes but only full sync every 5th time (so every 50 minutes).

all that being said... i hate this method.  it's buggy, it crashes, and i never trust it.  instead i have a script i keep in cron:

#!/bin/sh

PID=`pgrep offlineimap`

###
# what to do if it's still running? uncomment
# only one of the options below:
###
#[ -n "$PID" ] && kill $PID     # kill it and resync now
[ -n "$PID" ] && exit 1         # exit and let it finish
###

offlineimap -o -u Noninteractive.Quiet &>/dev/null &

this runs offlineimap only once in Noninteractive mode.  then i just set the line in cron to determine how often i sync:

*/3 * * * * /path/to/script

for every three minutes


Protip: i also add something like this to muttrc:

macro index Z   "<shell-escape>/usr/bin/offlineimap -q -o<enter>" "sync IMAP"

then i can just hit 'Z' in mutt to quick-sync immediately.

once i landed on this roundabout method, i havent changed it in almost 6 months.  been working great.

Last edited by brisbin33 (2009-09-04 16:54:32)

Offline

#9 2009-09-04 17:53:34

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

Thanks, you are really great !
I'll mark this as solved.


Sorry for any English mistakes, I am not a native speaker.

Offline

#10 2009-09-04 23:53:35

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,356

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

Offlineimap tends to crash for one of two reasons, either there's problems with network connectivity or issues with the mails its trying to upload/download. I use this script in cron:-

#!/bin/sh

# Run offlineimap through cron to fetch email periodically

ps aux | grep "\/usr\/bin\/offlineimap"

if [ $? -eq "0" ]; then
  logger -i -t offlineimap "Offlineimap still running."
  exit 0;
else
  logger -i -t offlineimap "Starting offlineimap..."
  offlineimap -u Noninteractive.Quiet
    if [ $? = 100 ]; then
        touch /home/data/Profiles/.offlineimapfailed;
    fi
fi

Basically checks every 5 minutes (set in cron) to see if its already running, start it up if it isn't (my offlineimap runs indefinitely). If its crashed I update the datestamp on a text file so my conky knows about it.

Advantage of using it this way is when they merge back the IDLE command, you'll be able to only sync once every half hour and still receive your messages along the way if needed, instead of only every X minutes as with a cron.

The mutt quick-sync is a good idea though. Unfortunately I have to use evolution...


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#11 2009-09-05 00:15:08

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

ngoonee that's quite nice.  my only minor comment is that you could use

if ps aux | grep -v grep | grep -q '/usr/bin/offlineimap' ; then
  ...
else
  ...
fi

instead.  ps aux will show the grep itself.

Last edited by brisbin33 (2009-09-05 00:16:27)

Offline

#12 2009-09-05 15:44:13

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,356

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

brisbin33 wrote:

ngoonee that's quite nice.  my only minor comment is that you could use

if ps aux | grep -v grep | grep -q '/usr/bin/offlineimap' ; then
  ...
else
  ...
fi

instead.  ps aux will show the grep itself.

In my case it doesn't, somehow...


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#13 2009-09-05 15:55:18

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

wow, that's pretty odd.

> ps aux | grep '/usr/bin/offlineimap'
patrick   4202  4.4  0.3 189808 12120 ?        Sl   11:54   0:00 /usr/bin/python /usr/bin/offlineimap -o -u Noninteractive.Quiet
patrick   4213  0.0  0.0   7772   952 pts/6    R+   11:54   0:00 grep --color=auto /usr/bin/offlineimap

oh well smile.

Offline

#14 2009-09-05 16:03:24

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

I tend to use "ps -e"


This silver ladybug at line 28...

Offline

#15 2009-11-17 01:10:51

moose jaw
Member
From: Milwaukee
Registered: 2007-08-20
Posts: 104

Re: [SOLVED] OfflineIMAP seems to have a syntax error in its code

brisbin33 wrote:
#!/bin/sh

PID=`pgrep offlineimap`

###
# what to do if it's still running? uncomment
# only one of the options below:
###
#[ -n "$PID" ] && kill $PID     # kill it and resync now
[ -n "$PID" ] && exit 1         # exit and let it finish
###

offlineimap -o -u Noninteractive.Quiet &>/dev/null &

Just stumbled upon this thread and am now enjoying a nice offlineimap + mutt (+msmtp) setup: thanks to all above!  I'm finding offlineimap much better than mutt's built-in IMAP, as others have noted.

For the benefit of anyone else who happens upon this thread, I thought I'd share one stupid beginner's mistake I made when using brisbin's script above to run offlineimap via cron: I named the script itself "offlineimap_sync".  Then, when I (or cron) ran the script, pgrep found the script's own PID in what is designed above as a search for offlineimap's PID, making $PID non-null, and exited without running offlineimap.  I couldn't figure out what was going on at first.  Sure enough, changing the name of the script to something without "offlineimap" in it solves the problem.  Duh.  Anyway, in case it's helpful...

(Also, for some reason on my machine "offlineimap" doesn't seem to run properly in the background, so I've removed the final "&" in the script above; again, in case this is helpful for someone else...)

Offline

Board footer

Powered by FluxBB