imapIO

Convenience classes and methods for processing IMAP mailboxes
Download

imapIO Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Publisher Name:
  • Roy Hyunjin Han
  • Publisher web site:
  • https://github.com/invisibleroads/

imapIO Tags


imapIO Description

Convenience classes and methods for processing IMAP mailboxes imapIO provides some convenience classes and methods for processing IMAP mailboxes. Since the classes are derived from the imaplib classes, all methods available in the imaplib classes are directly usable.Installation:easy_install -U imapIOUsage:# Connect to IMAP serverimport imapIOserver = imapIO.connect(host, port, user, password)# Select IMAP folderimport randommessageCount = server.cd(random.choice(server.folders))# For each email in the inbox,for email in server.walk(includes='inbox'): # Show information print print 'Date: %s' % email.whenUTC print 'Subject: %s' % email.subject.encode('utf-8') print 'From: %s' % email.fromWhom.encode('utf-8') print 'From (nickname): %s' % imapIO.clean_nickname(email.fromWhom) print 'To: %s' % email.toWhom.encode('utf-8') print 'CC: %s' % email.ccWhom.encode('utf-8') print 'BCC: %s' % email.bccWhom.encode('utf-8') # Set seen flag email.seen = False# For each email excluding the trash and drafts folders,for email in server.walk(excludes=): # Set deleted flag email.deleted = False# For each email satisfying the search criterion,emailCriterion = 'BEFORE 23-JAN-2005'emailGenerator = server.walk(excludes=, criterion=emailCriterion)for emailIndex, email in enumerate(emailGenerator): # Show flags print print email.flags # Save email in compressed format on hard drive emailPath = '%s.gz' % emailIndex partPacks = email.save(emailPath) # Extract attachments from email on hard drive for partIndex, filename, contentType, payload in imapIO.extract_parts(emailPath): print len(payload), filename.encode('utf-8')# Create a message in the inboximport datetimeserver.revive('inbox', imapIO.build_message( whenUTC=datetime.datetime(2005, 1, 23, 1, 0), subject='Subject', fromWhom='from@example.com', toWhom='to@example.com', ccWhom='cc@example.com', bccWhom='bcc@example.com', bodyText=u'text', bodyHTML=u'< html >text< /html >', attachmentPaths=))email = server.walk('inbox', criterion='FROM from@example.com TO to@example.com').next()email.deleted = Trueserver.expunge() Requirements: · Python What's New in This Release: · Reverted to set() for versions of Python < 2.7 that lack set literal syntax · Fixed tests for servers like Lotus Domino that do not update search indices


imapIO Related Software