Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:15:34+00:00 2026-05-26T06:15:34+00:00

I am trying to grab images in an embedded email. The problem is that

  • 0

I am trying to grab images in an embedded email. The problem is that the image that i save is unreadable and i can’t figure out why.
The email (saved as a file which i load in the beginning of the code):

MIME-Version: 1.0

Received: by 10.100.120.7 with HTTP; Tue, 18 Oct 2011 10:36:48 -0700 (PDT)

In-Reply-To: <8B4FDE07A4759840B84FD04B4C88100B010135E81D8C@fxildc03.forexmanage.com>

References: <8B4FDE07A4759840B84FD04B4C88100B010135E81D8C@fxildc03.forexmanage.com>

Date: Tue, 18 Oct 2011 19:36:48 +0200

Delivered-To: s.shpiz@gmail.com

Message-ID: <CAEb-As9XVmciajFAwEaFyF8CE4QG0t-Z5zFDDpMWXLqaBur1sA@mail.gmail.com>

Subject: openme

From: Simeon Shpiz <s.shpiz@gmail.com>

To: me <s.shpiz@gmail.com>

Content-Type: multipart/related; boundary=001636c5977303b92404af962ba6



--001636c5977303b92404af962ba6

Content-Type: multipart/alternative; boundary=001636c5977303b91d04af962ba5



--001636c5977303b91d04af962ba5

Content-Type: text/plain; charset=ISO-8859-1



****



--001636c5977303b91d04af962ba5

Content-Type: text/html; charset=ISO-8859-1

Content-Transfer-Encoding: quoted-printable



<div dir=3D"ltr"><div class=3D"gmail_quote"><div lang=3D"EN-US" link=3D"blu=

e" vlink=3D"purple"><div><p class=3D"MsoNormal"><span style=3D"font-size:11=

.0pt;color:#1F497D"><img width=3D"15" height=3D"13" src=3D"cid:image003.png=

@01CC8DCD.30A2A7C0"></span><span style=3D"font-size:11.0pt;color:#1F497D"><=

u></u><u></u></span></p>



</div>

</div></div><br></div>



--001636c5977303b91d04af962ba5--

--001636c5977303b92404af962ba6

Content-Type: image/png; name="image003.png"

Content-Transfer-Encoding: base64

Content-ID: <image003.png@01CC8DCD.30A2A7C0>

X-Attachment-Id: 3e79c375acccec3d_0.1



iVBORw0KGgoAAAANSUhEUgAAAA4AAAANCAIAAAAWvsgoAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAO

yAAADsMBrahYpwAAAItJREFUKFNj/P//PwNxgIk4ZWBVQFOBoBsMsGqrqqr6CgYsaNIPHz6EiMjJ

yb19+xbISE9PLy4uBjLQlSLrFBYWBnITExN9fHyADMJulZCQgOgnrFRUVJRYpXAnETb19evXxJr6

4sULiFJ8IfDt2zegii1btmRkZGBRKi8vjxbSwKjJysoCCjISnwYATtwwhahioZoAAAAASUVORK5C

YII=

--001636c5977303b92404af962ba6--

The python code i am using:

import email
from BeautifulSoup  import BeautifulSoup 

message = email.message_from_file(open(r'C:\shpiz\test\msg\12248'))
cid_list = []
images = []
for part in message.walk():
    if str(part.get_content_type()) == 'text/html':
        soup = BeautifulSoup(part.get_payload(decode=True))
        cid = '<%s>'%soup('img')[0]['src'][4:]
        cid_list.append(cid)

for part in message.walk():
    if part.get('Content-ID') in cid_list :
        images.append((part.get_filename(),part.get_payload(decode=True)))
for name, image in images:
    with open(r'c:\shpiz\test\%s'%name,'w') as f:
        f.write(image)

The image saved is unfortunately not good. (No program opens it).

I looked at the original and the new image files with notepad++ and there is a difference- there looks to be a line break my generated copy not present in the original. that’s not the only difference though as deleting the line in notepad++ didn’t make the image openable. The difference I described can be seen here

Would appreciate any assistance in finding the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:15:35+00:00Added an answer on May 26, 2026 at 6:15 am

    You’re writing the image in text mode and Python is mangling the line endings. Open it in wb mode to write it verbatim.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a reference to an image file out of a plist
So I'm trying to grab some images from another site, the problem is each
I am trying to grab a reference to images with src's in URI scheme.
I am trying to pass an image over python socket for smaller images it
I've been trying to develop an application with Netbeans RCP to grab images from
I'm trying to get the captions from images in Wordpress but I can't find
Rails 2.3.5 For a link_to image_tag', I've been trying to figure out how to
Im trying to grab the ids of the images using rails, pass those ids
I am trying to write a simple application that loads images that are stored
I am trying to serve the thumbnail of a file that resides in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.