Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

python email ..

Options
  • 15-10-2008 11:52am
    #1
    Closed Accounts Posts: 1,788 ✭✭✭


    Hi this is a continuation of my previous thread, I have the python reading emails and saving attachments, but when i resend the emails, its attaching ok .. but it's also showing the attachment in binary ... like below ..
    From: "royRogers" <roy.rogers@gmail.com>
    To: rizzzzz@zzzzzzz.com
    Subject: test......
    Content-Transfer-Encoding: 64bit
    
    hey test ignore please..
    <div dir="ltr">hey test ignore please.. <br><br></div>
    PHAgc3R5bGU9InRleHQtYWxpZ246IGNlbnRlcjsgZm9udC1zaXplOiAzMHB0OyBmb250LXdlaWdo
    dDogYm9sZDsgY29sb3I6IHdoaXRlOyBiYWNrZ3JvdW5kLWNvbG9yOiByZWQ7IHBhZGRpbmc6IDdw
    eDsiPkRldHRlIGVyIGVuIHRlc3RiZXN0aWxsaW5nPC9wPjxkaXYgc3R5bGU9InBhZGRpbmc6IDE1
    cHg7IHdpZHRoOiA3MDBweDsgZm9udC1mYW1pbHk6IEFyaWFsOyI+PGRpdiBzdHlsZT0id2lkdGg6
    IDEwMCU7IHBhZGRpbmc6IDVweDsgZm9udC1zaXplOiAyNnB0OyBmb250LXdlaWdodDogYm
    


    Then below the attachment is there in 'proper' format, how can i leave out all the giberish above, so far i can leave ALL the body out ... but not just the gibberish .. i need just the 'hey test ignore please..' part ..

    for line in email.Iterators.body_line_iterator(e):
    			if type(body) != type('MIME'):
    				body = body + line
    

    this will eliminate all from the body.. and just leave the attachment ..

    but is there a way to seperate gibberish from text , or from pythons point of view now it is all text ?


Comments

  • Registered Users Posts: 1,393 ✭✭✭Inspector Gadget


    Erm, if that's the actual content of the message, I don't see any MIME (RFC 1521, or google it) header information embedded in the message (I'm assuming that you've encoded the attachment as base64)?

    Here's an example taken from the Wikipedia page:
    MIME-version: 1.0
    Content-type: multipart/mixed; boundary="frontier"
    
    This is a message with multiple parts in MIME format.
    --frontier
    Content-type: text/plain
    
    This is the body of the message.
    --frontier
    Content-type: application/octet-stream
    Content-transfer-encoding: base64
    
    PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg
    Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
    --frontier--
    

    A quick glance at this gives away how it's done, and how the various parts of the e-mail are separated out. Note that normally an e-mail message will use a randomly generated gob of characters instead of the simple word "frontier", but you get the idea. You specify how the boundaries between each chunk/attachment are defined, and then (in the headers at the top of each chunk) what's in there, and how it's encoded.

    Does this help at all?
    Gadget


Advertisement