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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:05:42+00:00 2026-05-13T10:05:42+00:00

I am trying to write a program that monitors an IMAP mailbox and automatically

  • 0

I am trying to write a program that monitors an IMAP mailbox and automatically copies every new incoming message into an “Archive” folder. I’m using imaplib2 which implements the IDLE command. Here’s my basic program:

M = imaplib2.IMAP4("mail.me.com")
M.login(username,password)
lst = M.list()
assert lst[0]=='OK'
for mbx in lst[1]:
    print "Mailboxes:",mbx

def process(m):
    print "m=",m
    res = M.recent()
    print res


M.select('INBOX')
M.examine(mailbox='INBOX',callback=process)
while True:
    print "Calling idle..."
    M.idle()
    print "back from idle"
M.close()
M.logout()

It prints the mailboxes properly and runs process() when the first change happens to the mailbox. But the response from recent() doesn’t make sense to me, and after the first message I never get any other notifications.

Anyone know how to do this?

  • 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-13T10:05:43+00:00Added an answer on May 13, 2026 at 10:05 am

    See example and references in python-imap-idle-with-imaplib2 (Wayback Machine snapshot).
    The module involves threading, you should pay attention to event synchronization.

    The example suggests synchronizing with events, and leaves mail processing to the reader:

    # The method that gets called when a new email arrives. 
    # Replace it with something better.
    def dosync(self):
        print "Got an event!"
    

    Taking a hint from the question, "something better" can be:

    # Replaced with something better.
    def dosync(self):
        print "Got an event!"
        res = self.M.recent()
        print res
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 315k
  • Answers 315k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should take a look at Elsa. It is relatively… May 13, 2026 at 11:13 pm
  • Editorial Team
    Editorial Team added an answer Objective-C has the concept of a Protocol, which is the… May 13, 2026 at 11:13 pm
  • Editorial Team
    Editorial Team added an answer To load an image from a JAR resource use the… May 13, 2026 at 11:13 pm

Related Questions

I am trying to write a cross-platform python program that would run in the
I am trying to finish a homework program that compares a string with a
I am trying to write a program that allows a binary to be run,
I am trying to write a program that displays the integers between 1 and
I am trying to write a program that uses a timer, duration, start time

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.