OfflineIMAP / offlineimap

Read/sync your IMAP mailboxes (python2) [LEGACY: move to offlineimap3]
http://www.offlineimap.org
Other
1.78k stars 360 forks source link

percent (%) sign in configuration raises exception #114

Closed danmilon closed 10 years ago

danmilon commented 10 years ago

An exception is raised when the configuration contains the "%" sign in values (e.g. password). Do you know any workaround for this, or a way to fix it?

ERROR: Exceptions occurred during the run!
ERROR: While attempting to sync account 'xxx@xxx.com'
  '%' must be followed by '%' or '(', found: '%!f'

Traceback:
  File "/usr/lib/python2.7/site-packages/offlineimap/accounts.py", line 241, in syncrunner
    self.__sync()
  File "/usr/lib/python2.7/site-packages/offlineimap/accounts.py", line 303, in __sync
    remoterepos.getfolders()
  File "/usr/lib/python2.7/site-packages/offlineimap/repository/IMAP.py", line 322, in getfolders
    imapobj = self.imapserver.acquireconnection()
  File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 418, in acquireconnection
    self.__authn_helper(imapobj)
  File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 327, in __authn_helper
    if func(imapobj):
  File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 253, in __authn_plain
    imapobj.authenticate('PLAIN', self.__plainhandler)
  File "/usr/lib/python2.7/site-packages/offlineimap/imaplib2.py", line 648, in authenticate
    typ, dat = self._simple_command('AUTHENTICATE', mechanism.upper())
  File "/usr/lib/python2.7/site-packages/offlineimap/imaplib2.py", line 1615, in _simple_command
    return self._command_complete(self._command(name, *args), kw)
  File "/usr/lib/python2.7/site-packages/offlineimap/imaplib2.py", line 1354, in _command
    literal = literator(data, rqb)
  File "/usr/lib/python2.7/site-packages/offlineimap/imaplib2.py", line 2163, in process
    ret = self.mech(self.decode(data))
  File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 162, in __plainhandler
    passwd = self.__getpassword()
  File "/usr/lib/python2.7/site-packages/offlineimap/imapserver.py", line 111, in __getpassword
    self.password = self.repos.getpassword() or \
  File "/usr/lib/python2.7/site-packages/offlineimap/repository/IMAP.py", line 269, in getpassword
    password = self.getconf('remotepass', None)
  File "/usr/lib/python2.7/site-packages/offlineimap/CustomConfig.py", line 134, in getconf
    self.getconfig().get)
  File "/usr/lib/python2.7/site-packages/offlineimap/CustomConfig.py", line 127, in _confighelper_runner
    return defaultfunc(*(lst + list(args)))
  File "/usr/lib/python2.7/site-packages/offlineimap/CustomConfig.py", line 30, in getdefault
    return self.get(*(section, option) + args, **kwargs)
  File "/usr/lib/python2.7/ConfigParser.py", line 623, in get
    return self._interpolate(section, option, value, d)
  File "/usr/lib/python2.7/ConfigParser.py", line 691, in _interpolate
    self._interpolate_some(option, L, rawval, section, vars, 1)
  File "/usr/lib/python2.7/ConfigParser.py", line 732, in _interpolate_some
    "'%%' must be followed by '%%' or '(', found: %r" % (rest,))
spaetz commented 10 years ago

You can use %% to encode the percentage sign. It is IMHO documented in the stock configbfile

Sent from mobile phone. Please excuse brevity

danmilon commented 10 years ago

You're right. Sorry bout that!

m4ci3k2 commented 7 years ago

It is, but maybe a better error message would be useful? For example a second line saying If you want literal % in your config file, replace it with %% would directly tell the solution. It is not very easy to find this information if you don't know where to look.

nicolas33 commented 7 years ago

Added to the FAQ.

chris001 commented 7 years ago

If the config parser would catch exception ConfigParser.InterpolationError Base class for exceptions raised when problems occur performing string interpolation. then it could print the user-friendly advice how to fix the config file entry by adding %, and even print which line is the offending line. https://github.com/OfflineIMAP/offlineimap/blob/master/offlineimap/mbnames.py#L176