get_payload problem with large mail attachments

hungryblank at hungryblank at
Fri Oct 14 12:37:01 CEST 2005

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/", line 44, in ?
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':
        # 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')

More information about the Python-list mailing list