Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Remove some images from a mail message

Thread Tools

Remove some images from a mail message

Jason Friedman
Posts: n/a
I will be receiving email that contains, say, 10 images, and I want to
forward that message on after removing, say, 5 of those images. I will
remove based on size, for example 1679 bytes. I am aware that other images
besides the unwanted ones could be 1679 bytes but this is unlikely and the
impact of mistakes is small.

I have figured out how to compose and send an email message from parts:
from, to, subject, and some images. I was planning to read the incoming
message, write the images I want to keep to files, then use those files to
construct the outgoing message.

I cannot figure out how to read the incoming message and extract the images.

message_in = email.message_from_binary_file(open(file_name, "rb"))
for part in message_in.walk():
print("-" * 80)
print("type: " + part.get_content_maintype())
for key, value in part.items():
print("key: " + key)
print("value: " + value)


type: multipart
key: Return-Path
value: <(E-Mail Removed)>
key: X-Original-To
value: myuser@myhost


key: Content-Type
value: multipart/alternative;
boundary="_000_A9E5330AAB8D0D4E8F9372F872EE8504010 458F671hostden_"

--_000_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChos tden_--

--_010_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChos tden_
Content-Type: image/png; name="image001.png"
Content-Description: image001.png
Content-Disposition: inline; filename="image001.png"; size=9257;
creation-date="Mon, 15 Apr 2013 17:48:29 GMT";
modification-date="Mon, 15 Apr 2013 17:48:29 GMT"
Content-ID: <(E-Mail Removed)9801A60>
Content-Transfer-Encoding: base64




I'm guessing my image is in there, how do I get it out?

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Is there any way to get the raw image data from a Nikon Coolpix S8200 P&S camera? Tony Cooper Digital Photography 16 04-17-2013 07:49 PM
From IrfanView to Desktop wallpaper? Terry Pinnell Digital Photography 5 04-10-2013 11:11 PM
Re: retrieving data from a plot in python. Gary Herron Python 0 04-09-2013 06:00 PM
retrieving data from a plot in python. Debashish Saha Python 1 04-09-2013 05:58 PM
when I read gzipped response from web-servers, GzipReader returnssometimes 'invalid compressed data -- crc error' Ruby 0 04-08-2013 03:51 PM