473,246 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

Extracting email attachment when is_multipart() is False

I need to write a script which should extract the attachment from a text
file, which is saved as MIME mail message. Unfortunatelly,
Message.is_multipart() returns False so msg.get_payload() returns the
complete message. What I need is the attachment only. Is it possible to do
that with standard email package without the actual string level parsing?

This is how my file/message looks like:

====== start here ========
This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C3B347.DBEA9660
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

CONTENT

signature, etc

------=_NextPart_000_0026_01C3B347.DBEA9660
Content-Type: application/octet-stream;
name="filename.csv"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="filename.csv"

10012;20031118;292.67;4
101;23;19.98;2;39.96
102;24;21.89;4;87.56

------=_NextPart_000_0026_01C3B347.DBEA9660--

====== end here ========

So, I obviously need this part only:

10012;20031118;292.67;4
101;23;19.98;2;39.96
102;24;21.89;4;87.56

Python 2.3.2 on windows.

Thanks and regards,

Davor
Jul 18 '05 #1
4 3087
"Davor Cengija" <dc****************@inet.hr> writes:
I need to write a script which should extract the attachment from a text
file, which is saved as MIME mail message. Unfortunatelly,
Message.is_multipart() returns False so msg.get_payload() returns the [...] This is how my file/message looks like:

====== start here ========
This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C3B347.DBEA9660
Content-Type: text/plain;

[...]

You seem to be missing the RFC 822 headers (From, To, Subject, etc.).
John
Jul 18 '05 #2
John J. Lee wrote:
"Davor Cengija" <dc****************@inet.hr> writes:
This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C3B347.DBEA9660
Content-Type: text/plain;

[...]

You seem to be missing the RFC 822 headers (From, To, Subject, etc.).


Yes, that's true. The question is if it's easier to write a parser for that
kind of messages or to force the message producing application to output the
headers as well. We'll see...

Thanks
Jul 18 '05 #3
On Wed, 26 Nov 2003 08:06:15 +0100, Davor Cengija wrote:
John J. Lee wrote:
"Davor Cengija" <dc****************@inet.hr> writes:
This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C3B347.DBEA9660
Content-Type: text/plain;

[...]

You seem to be missing the RFC 822 headers (From, To, Subject, etc.).


Yes, that's true. The question is if it's easier to write a parser for that
kind of messages or to force the message producing application to output the
headers as well. We'll see...


You have a third option, which I would try if you can't get the
message producer to do it correctly: slap some RFC822 headers on the
beginning, and then ignore them in the parsed message object. After
all, if the rest of the data is correctly formatted, use the existing
tested MIME parser. Prepending some "bogus" RFC822 headers would be
rather trivial to do.

-D

--
"Piracy is not a technological issue. It's a behavior issue."
--Steve Jobs

www: http://dman13.dyndns.org/~dman/ jabber: dm**@dman13.dyndns.org
Jul 18 '05 #4
Derrick 'dman' Hudson <dm**@dman13.dyndns.org> writes:
On Wed, 26 Nov 2003 08:06:15 +0100, Davor Cengija wrote:

[...]
You seem to be missing the RFC 822 headers (From, To, Subject, etc.).


Yes, that's true. The question is if it's easier to write a parser for that
kind of messages or to force the message producing application to output the
headers as well. We'll see...


You have a third option, which I would try if you can't get the
message producer to do it correctly: slap some RFC822 headers on the
beginning, and then ignore them in the parsed message object. After

[...]

Or read the docs & code for the email module, to figure out how to
persuade it to take the messages without the headers.
John
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Wald | last post by:
Hello group, I've got a script here that sends emails with an attachment to an email address that is retrieved from an html form. The email sending code is include below. The problem: when...
4
by: Paul Schmidt | last post by:
Dear list: I am new to python, and I am trying to figure out the short answer on something. I want to open a POP3 mailbox, read the enclosed mail using the POP3 module, , and then process it...
3
by: Joh | last post by:
hello, i'm looking for a way to get total size of an email (with its attached files) using library such as poplib, or ? can someone help me or give me an url from where to start ? thx
1
by: Arenz, Ralph | last post by:
hi all, my problem is to get a tiff-file-attachment out of an email sent by a fax-server. When i try this with "get_payload(decode='True')" i get additional informations, looks like...
2
by: Dave G | last post by:
I'm writing a function to look for particular emails in my Inbox and when it finds one it copies the attachment to a folder and then deletes the email. It spots the email by looking for certain...
19
by: 叮叮当当 | last post by:
hi, all when a email body consist with multipart/alternative, i must know when the boundary ends to parse it, but the email lib have not provide some function to indicate the boundary end,...
4
by: Sergey Dorofeev | last post by:
Hello. Why does not work? -------------- import email.message import smtplib import time m=email.message.Message()
3
by: Steven Allport | last post by:
I am working on processing eml email message using the email module (python 2.5), on files exported from an Outlook PST file, to extract the composite parts of the email. In most instances this...
3
by: jambonjamasb | last post by:
Hi I have two tables: email_tbl Data_table Data table is is used to create a Form Data_form
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.