Thanks for the review!

On Sun 2019-09-15 21:39:33 -0300, David Bremner wrote:
> 1) It would be nice if path= supported ~ expansion, as getmail does;
> that's easy to work around for one machine, but it's harder to share
> configs between different machines.

gotcha, i've added that now:

diff --git a/imap-dl b/imap-dl
index 97fa4a8..a2ae033 100755
--- a/imap-dl
+++ b/imap-dl
@@ -97,12 +97,12 @@ def pull_msgs(configfile):
     if rtype.lower() != 'simpleimapsslretriever':
         raise Exception('Expected retriever.type to be SimpleIMAPSSLRetriever, got %s'%(rtype,))
     # FIXME: handle `retriever.record_mailbox`
-    # FIXME: handle leading ~-style globbing for destination.type
     dtype = conf.get('destination', 'type', fallback='Maildir')
     if dtype.lower() != 'maildir':
         raise Exception('expected destination.type to be Maildir, got %s'%(
             dtype))
     dst = conf.get('destination', 'path')
+    dst = os.path.expanduser(dst)
     if not os.path.isdir(dst):
         raise Exception('expected destination directory, but %s is not a directory'%(dst,))
     ca_certs = conf.get('retriever', 'ca_certs', fallback=None)
and i've updated the imap-dl branch on
https://salsa.debian.org/dkg/mailscripts to include it.

> 2) ./imap-dl ~/.getmail/getmailrc crashes with
> Traceback (most recent call last):
>   File "./imap-dl", line 196, in <module>
>     pull_msgs(confname)
>   File "./imap-dl", line 166, in pull_msgs
>     sizes[m['uid']], m['size']))
> Exception: summary said 27777 octets, fetch sent 7207
>
> My getmailrc looks like
>
> [retriever]
> type=SimpleIMAPSSLRetriever
> server=smtp.office365.com
> username=m...@example.com
> password=rootme
>
> [destination]
> type=Maildir
> path=/home/bremner/Maildir/foo
>
> [options]
> delete=1
>
> It seems like getmail does indeed fetch 27777 bytes for that message,
> I'm not sure what the partial fetch indeicates. I can't rule out malice
> or incompetance on the part of the imap provider.

hm, that's very odd.  is this replicable with every message that comes
into this account, or just with some specific ones?  Can you show me the
relevant lines (appropriately redacted) from the output of:

    getmail --trace -r /path/to/getmailrc

For example, i see something like this:

    …
    select(INBOX) returned message count of 1
    _getmsglist() [_retrieverbases.py:1521] trace
    _parse_imapcmdresponse() [_retrieverbases.py:1356] trace
    command FETCH ('1:1', '(UID RFC822.SIZE)') response ['1 (UID 167 
RFC822.SIZE 1845)']
    _parse_imapattrresponse() [_retrieverbases.py:1401] parsing attributes 
response line 1 (UID 167 RFC822.SIZE 1845)
    _parse_imapattrresponse() [_retrieverbases.py:1424] got {'rfc822.size': 
'1845', 'uid': '167'}
    __len__() [_retrieverbases.py:852] trace
      message 1318777879/167 ...
    _getmsgbyid() [_retrieverbases.py:1683] trace
    _getmsgpartbyid() [_retrieverbases.py:1583] trace
    _getmboxuidbymsgid() [_retrieverbases.py:1349] trace
    retrieving body for message "167"
    _parse_imapuidcmdresponse() [_retrieverbases.py:1381] trace
    command uid FETCH ('167', '(BODY.PEEK[])') response [('1 (UID 167 BODY[] 
{1845}', 'Return-Path:…


The key things to note there are that 1845 in the response to
RFC822.SIZE, and the {1845} before the BODY[] comes back.

i think the only difference in terms of commands on the wire is that
imap-dl is requesting BODY[], but getmail is requesting BODY.PEEK[], but
that shouldn't cause the problem you describe.  You can rule it out with
this minor patch, though:

--- a/imap-dl
+++ b/imap-dl
@@ -143,7 +143,7 @@ def pull_msgs(configfile):
         # FIXME: fetch in batches or singly instead of all-at-once?
         # FIXME: rolling deletion?
         # FIXME: asynchronous work?
-        resp = imap.uid('fetch', uids, '(UID BODY[])')
+        resp = imap.uid('FETCH', uids, '(UID BODY.PEEK[])')
         if resp[0] != 'OK':
             raise Exception('UID fetch failed %s'%(resp[0]))
         for f in resp[1]:

can you tell me whether you can replicate the problem in this way?

    --dkg

Attachment: signature.asc
Description: PGP signature

Reply via email to