473,225 Members | 1,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

Set header from IMAP

Dear List,

I'm trying to figure out, how to change the header of an e-mail that is
accessed by an IMAP object.
There is some code below (not a complete program). The key function is
the filter_mail function. It should move/delete/change/export messages,
based on their header. For exporting messages, I use this: "typ,dat =
self.conn.uid('FETCH',self.uid,'(RFC822)') ". The only thing I don't
know how to do, is to insert/modify/delete custom headers in e-mails. I
was looking for this on Google and the Python cookbook, but I did not
find anyting useful. Please help.

import local
import imaplib

class IMAPError(Exception):

def check_imap_error((typ,data)):
if (typ != 'OK'):
raise IMAPError((typ,data))

def getnewimapconnection():
conn = imaplib.IMAP4_SSL(local.IMAP_HOST)
check_imap_error(conn.LOGIN(local.IMAP_LOGIN,local .IMAP_PWD))
return conn
conn = getnewimapconnection()
cnt = 0
for inputfolder in (local.SOURCE_FOLDER,local.SOURCE_FOLDER2):
typ,data = conn.select(inputfolder)
cnt = int(data[0])

if cnt 0:
self.logger.info("Processing %s messages in %s",cnt,inputfolder)
# Get UID and RFC822 headers for all messages
typ, items = conn.fetch('1:%s'%cnt, '(UID RFC822.HEADER)')
check_imap_error((typ, items))
for item in items:
if isinstance(item,tuple):
uid = item[0].split()[2]
headers = item[1]
parser = email.Parser.Parser()
parsed = parser.parsestr(headers,True)
self.logger.info("No new messages in %s",inputfolder)

Nov 13 '06 #1
0 967

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Ian Marlier | last post by:
I'm trying to get a PHP-based webmail setup going, but I'm running into a problem with IMAP authentication. Specifically, the PHP IMAP extension is trying to log in using CRAM-MD5 authentication,...
by: Fabian Müller | last post by:
Hello, I would like to access (open) my remote IMAP Mailbox with the imap_open() function in PHP Version 5.0.4. The Mailbox is located at the german provider freenet.de. The imap_open()...
by: dekoffie | last post by:
Hello there, I'm trying to create a connection with an IMAP server which is secured through SSL. I can get the connection just fine, and I get a first respone from the server. But then I send...
by: chirag | last post by:
i want a IMAP server for windows so that i can retrive incoming mails. I use mssql server to store user information. i need IMAP server to develop project i.e mail system can any body sent me...
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
by: Petri Savolainen | last post by:
Hello, Is there a way to get at the "Received" header(s) or is there something in imaplib or imap server implementations that hides these? If not, what IMAP FETCH command should be used? I've...
by: contactme | last post by:
Hi, Is it possible to open concurrent connections using Net::IMAP::Simple library ? My IMAP server allows 4 connections per ip, so I am having following problems while using Net::IMAP::Simple and...
by: gregpinero | last post by:
I'm trying to get a list of messages from GMAIL using it's new IMAP access. So far I've tried running this command but it just hangs. Any ideas? I figured that's the first line to run from...
by: mp- | last post by:
I want to be able to allow people to check their email from my PHP online application. Given only the users 1) email address, 2) username (if applicable) and 3) password - how can I auto detect...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.