Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you're asking what I think you're asking, here's what to do:</p> <p>First, fetch the <code>BODYSTRUCTURE</code>. Assuming gmail's IMAP server supports this, you'll get back something like this:</p> <pre><code>(("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "QUOTED-PRINTABLE" 56 1 NIL NIL NIL NIL) ("TEXT" "HTML" ("CHARSET" "UTF-8") (NAME "") NIL NIL "BASE64" 12345 NIL ("attachment" ("FILENAME" "")) NIL NIL) ("IMG" "JPEG" (NAME "funny picture") NIL NIL "BASE64" 56789 NIL ("attachment" ("FILENAME" "image.jpg")) NIL NIL)) "MIXED" ("BOUNDARY" "----_=_NextPart_001_1234ABCD.56789EF0") NIL NIL NIL) </code></pre> <p>And then fetch the <code>(BODY ENVELOPE)</code> is the structure has one.</p> <p>If you look at <a href="http://tools.ietf.org/html/rfc3501#section-7.4.2" rel="nofollow">RFC3501 7.4.2</a>, it explains how to deal with these.</p> <p>Once you've determined that the <code>(BODY[1])</code> and <code>(BODY[2])</code> are the plain-text and HTML versions of the main content, and <code>(BODY[3])</code> is the first real attachment, you download the plain-text body by fetching <code>(BODY[1])</code>, and you've got the name of the attachment from the structure.</p> <p>Sorry there's no code here. I don't think either <code>imaplib</code> or any of the stdlib MIME- and mail-related modules will do the hard part for you (interpreting the structure), but I haven't actually checked, so I'd look there first, and, if not, go to PyPI to see if anyone else has already written the code.</p> <p>Well, actually, first I'd just fetch <code>BODYSTRUCTURE</code>, <code>(BODY ENVELOPE)</code> and <code>(BODY[3])</code> for a specific message to make sure gmail has complete support before writing a whole mess of code…</p> <p>PS, if worst comes to worst, if your use case is as simple and rigid as you described, you can just always fetch <code>BODYSTRUCTURE</code> and <code>(BODY[1])</code>, fall back to <code>RFC822</code> if that fails, and get the attachment names by running a hacky regexp on the structure instead of a real parse. I wouldn't write this for anything but a one-shot script or a quick&amp;dirty prototype to learn about gmail, but for those cases, I probably would.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload