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 8386923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:04:42+00:00 2026-06-09T18:04:42+00:00

I have an email message obtained via Python’s email.parser module: parser = email.parser.Parser() msg1

  • 0

I have an email message obtained via Python’s email.parser module:

parser = email.parser.Parser()
msg1 = parser.parse(sys.stdin)

I would like to create a copy of this object, but I’m not sure how best to go about that. I can use the copy module…

msg2 = copy.deepcopy(msg1)

…but given that a MIME message may contain a somewhat arbitrary tree of parts I’m not sure if this is the right solution or not. I could serialize and reparse the message…

msg2 = parser.parse(msg1.as_string())

…but the documentation suggests that the as_string method may not always do the right thing. I can create a StringIO object and use a generator…

buf = String()
g = email.generator.Generator(buf)
g.flatten(msg1)
msg2 = parser.parse(buf.getvalue())

…but that seems like an awful lot of work to copy something that’s already been parsed once.

Using the copy module seems like the simplest solution, but I’m unfamiliar with the copy module. Am I doing the right thing?

  • 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-06-09T18:04:44+00:00Added an answer on June 9, 2026 at 6:04 pm

    Since it is a MIME message, you may be able to assume that no matter how nested an attribute may be, there will be an end. If so, deepcopy should do a recursive copy on every attribute of the message, so you will end up with the right thing doing copy.deepcopy.

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

Sidebar

Related Questions

I have an email message which looks like this: Hey how are you? On
i have printer status reports sent on my email. i would like to download
I have made a php page that sends an email message with multiple attachments.
I have a web application that uses the CDO Message object to email reports.
I have a jquery function for sending email with ajax request; function sendMail(from,to,subject,message){ var
I have the following form: echo $this->Form->input('Person.name'); echo $this->Form->input('Person.phone'); echo $this->Form->input('Person.email'); echo $this->Form->input('Message.0.plainmsg'); echo
I have email addresses like user1@gmail.com , user2@ymail.com user3@hotmail.com ... etc. I want a
I have a email multi-part message which I am using to send failed message
I have this code here where I retrieve an attachment from an Email Message
Just want a basic understand of what parts a email message may have. I

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.