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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:10:57+00:00 2026-06-06T18:10:57+00:00

I inadvertently marked all the messages in my inbox as read with this python

  • 0

I inadvertently marked all the messages in my inbox as read with this python statement:

status, data = conn.uid('fetch', fetch_uids, '(RFC822)')

But I was able to walk through all the parts of the message with the following set of statments:

email_message = email.message_from_string(data[0][1])
for part in email_message.walk():
  print '\n'
  print 'Content-Type:',part.get_content_type()
  print 'Main Content:',part.get_content_maintype()
  print 'Sub Content:',part.get_content_subtype()

The output:

Content-Type: multipart/mixed
Main Content: multipart
Sub Content: mixed


Content-Type: multipart/alternative
Main Content: multipart
Sub Content: alternative


Content-Type: text/plain
Main Content: text
Sub Content: plain


Content-Type: text/html
Main Content: text
Sub Content: html

I found that if I used this statement instead:

status, data = conn.uid('fetch', fetch_uids, '(RFC822.HEADER BODY.PEEK[1])')

that I wouldn’t mark all of my messages read. However, I also wouldn’t get all the parts of the message:

Content-Type: multipart/mixed
Main Content: multipart
Sub Content: mixed

I tried to read the manual for imaplib here, but the word “peek” is not mentioned. My question is, how do I get all the parts of the message while not marking my messages as read? Thanks.

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

    If you want just the headers, but still want the message to be left marked unread (UNSEEN), it requires two commands fetch and then store:

    # get uids of unseen messages
    result, uids = conn.uid('search', None, '(UNSEEN)')
    
    # convert these uids to a comma separated list
    fetch_ids = ','.join(uids[0].split())
    
    # first fetch the headers, this will mark them read (SEEN)
    status, headers = conn.uid('fetch', fetch_ids, '(RFC822.HEADER)')
    
    # now mark each message unread (UNSEEN)
    status1, flags = conn.uid('store', fetch_ids,'-FLAGS','\\Seen')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I inadvertently posted revisions to this previous post when I meant to update subsequent
I'm migrating a VSS repository to SVN and inadvertently included all of the _vti_cnf,
I've fixed this issue before (inadvertently) and I'm coming across this again. Hopefully someone
This may sound impossible but read on. I need to learn jQuery a little
In one of my builds for an iPhone app, I had inadvertently created a
I have a Sitecore/ASP.NET projects that I'm developing. Today at some point I inadvertently
I have inadvertently svn-deleted a file with svn del --targets del.txt . Now, I'd
I went out to my github repo and discovered that I had inadvertently added
I have a MKMap with a series of MKAnnotations , all of which are
I recently deployed inadvertently a debug version of our game typrX (typing races at

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.