473,396 Members | 1,966 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,396 software developers and data experts.

get_payload problem with large mail attachments

I'm having troubles with a script that uses the get_payload function.
My script just works perfectly if I use it with attachment up to 8 Mb.
If the attachment are more than 8 Mb large, the script exits with a
TypeError exception.
IMHO when get_payload try to convert the attachment in a single string
it occours in some size limit.
How can I fix it?

I'm using python-2.3.3 on a SuSE 9.1 distro

The error raised is

Traceback (most recent call last):
File "/usr/local/sbin/mailbox2home.py", line 44, in ?
fp.write(part.get_payload(decode=1))
TypeError: argument 1 must be string or read-only buffer, not None

and this is the slice of code where the error occours.

for message in messages:
for part in message.walk():
# multipart/* are just containers
if part.get_content_maintype() == 'multipart':
continue
# Applications should really sanitize the given filename so
that an
# email message can't be used to overwrite important files
filename = part.get_filename()
if not filename:
ext = mimetypes.guess_extension(part.get_type())
if not ext:
# Use a generic bag-of-bits extension
ext = '.bin'
filename = 'part-%03d%s' % (counter, ext)
counter += 1
fp = open(os.path.join(dir, filename), 'wb')
fp.write(part.get_payload(decode=1))
fp.close()

Oct 14 '05 #1
2 2467
hu*********@gmail.com wrote:
I'm having troubles with a script that uses the get_payload function.
My script just works perfectly if I use it with attachment up to 8 Mb.
If the attachment are more than 8 Mb large, the script exits with a
TypeError exception.
IMHO when get_payload try to convert the attachment in a single string
it occours in some size limit.
How can I fix it? Traceback (most recent call last):
File*"/usr/local/sbin/mailbox2home.py",*line*44,*in*?
fp.write(part.get_payload(decode=1))
TypeError: argument 1 must be string or read-only buffer, not None
None seems to be the expected result of get_payload(decode=1) for multipart
parts.
if part.get_content_maintype() == 'multipart':
continue


Could it be that your test for multipart isn't correct? I would try

if part.is_multipart():
continue

Peter

Oct 14 '05 #2
While I don't intend to stir up a hornet's nest, I feel an
obligation to point out that an 8Mb email attachment should
set off warning bells. I don't believe that SMTP email
is very efficient at moving such large files around and that
there are other methods for moving them more efficiently.
I've found that most email servers are configured to reject
email messages that are larger than 2-4Mb. Maybe it is time
to back up and look at WHY you even have attachments that are
that large? Just a suggestion.

-Larry

hu*********@gmail.com wrote:
I'm having troubles with a script that uses the get_payload function.
My script just works perfectly if I use it with attachment up to 8 Mb.
If the attachment are more than 8 Mb large, the script exits with a
TypeError exception.
IMHO when get_payload try to convert the attachment in a single string
it occours in some size limit.
How can I fix it?

I'm using python-2.3.3 on a SuSE 9.1 distro

The error raised is

Traceback (most recent call last):
File "/usr/local/sbin/mailbox2home.py", line 44, in ?
fp.write(part.get_payload(decode=1))
TypeError: argument 1 must be string or read-only buffer, not None

and this is the slice of code where the error occours.

for message in messages:
for part in message.walk():
# multipart/* are just containers
if part.get_content_maintype() == 'multipart':
continue
# Applications should really sanitize the given filename so
that an
# email message can't be used to overwrite important files
filename = part.get_filename()
if not filename:
ext = mimetypes.guess_extension(part.get_type())
if not ext:
# Use a generic bag-of-bits extension
ext = '.bin'
filename = 'part-%03d%s' % (counter, ext)
counter += 1
fp = open(os.path.join(dir, filename), 'wb')
fp.write(part.get_payload(decode=1))
fp.close()

Oct 14 '05 #3

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

Similar topics

0
by: pruebauno | last post by:
Hello all, I am having issues compiling Python with large file support. I tried forcing the configure script to add it but then it bombs in the make process. Any help will be appreciated. ...
2
by: Osiris Sawiris | last post by:
I inherited an Inventory control application that updates the stock from the branches at the end of each day. We receive the stock transactions via e-mail attachments (Excel Sheets). Those...
24
by: Salad | last post by:
Every now and then I see ads that state something like "Experience with Large Databases ...multi-gig...blah-de-blah" And I have to laugh. What's the difference between a large or small database? ...
6
by: grunes | last post by:
I wish to fread a few thousand bytes at a time in turn from several very large files from a DVD data disk, under Redhat Fedora Linux. When this is done the DVD drive wastes a lot of time and...
1
by: Mark | last post by:
Hi, I've seen some postings on this but not exactly relating to this posting. I'm reading in a large mail message as a string. In the string is an xml attachment that I need to parse out and...
14
by: tomer | last post by:
Clear DayHello, I have implemented a download manger in .NET that overrides Internet Explorer's bult-in download manager. I using HttpWebRequest/Response to download the files. All is working...
0
by: ARC | last post by:
Hello all, I have a question that I hope someone can help with. I have an Access 97 App, and I allow the user 2 options for e-mailing: MSMapi and MS Outlook 2000/XP. I have a user who is having...
11
by: shror | last post by:
Hi every body, Please I need your help solving my php mail() function problem that the code is appearing in the view source and I dont know whats the problem where I am using another page tto test...
1
by: rengaraj | last post by:
guys..,i just wanna know, what the impact if we use jar files with large size. in our web application ?... i mean ...let say i've a servlet/jsp container. and in the folder WEB-INF\lib ...many file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.