473,915 Members | 5,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Laszlo
import local
import imaplib

class IMAPError(Excep tion):
pass

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

def getnewimapconne ction():
conn = imaplib.IMAP4_S SL(local.IMAP_H OST)
check_imap_erro r(conn.LOGIN(lo cal.IMAP_LOGIN, local.IMAP_PWD) )
return conn
conn = getnewimapconne ction()
cnt = 0
try:
for inputfolder in (local.SOURCE_F OLDER,local.SOU RCE_FOLDER2):
typ,data = conn.select(inp utfolder)
check_imap_erro r((typ,data))
cnt = int(data[0])

if cnt 0:
self.logger.inf o("Processing %s messages in %s",cnt,inputfo lder)
# Get UID and RFC822 headers for all messages
typ, items = conn.fetch('1:% s'%cnt, '(UID RFC822.HEADER)' )
check_imap_erro r((typ, items))
for item in items:
if isinstance(item ,tuple):
uid = item[0].split()[2]
headers = item[1]
parser = email.Parser.Pa rser()
parsed = parser.parsestr (headers,True)
filter_mail(con n,uid,parsed)
conn.expunge()
else:
self.logger.inf o("No new messages in %s",inputfolder )
finally:
conn.logout()

Nov 13 '06 #1
0 990

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

Similar topics

0
3145
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, which my IMAP server doesn't support. Is there a way to make PHP IMAP use just plain login authentication? Thanks, Ian (ian@onepost.net)
1
3289
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() function does not produce an error message as you can see below. But when I call the imap_headers() function the warning message mentioned in the subject as well as below is returned.
0
4006
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 out my login string, and it does not seem to arrive at the server, because I don't get an answer returned! After some time, I receive a message from the server saying that I've been idle for too long, and then the connection gets closed.. But why...
3
2199
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 IMAP server.
2
7589
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. Any help appreciated! The ordeal is a follows I am using Solaris 10 with php5.1.1. GCC:
2
2324
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 used for example "BODY" and it always returns empty ("\r\n"). Despite the Received - header existing, as demonstrated by taking a look at message sources via desktop email clients. I need to get at the Received-for header to figure out at which...
0
1408
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 Net::IMAP::Simple::SSL libraries: 1) The method new returns a valid connection even on 5th try, though the login fails as it looks like IMAP->login somehow knows that 5th object is not valid..Is it possible ? 2) Somtime, the script fails at the...
4
11799
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 this example: http://docs.python.org/lib/imap4-example.html Here are the configuration settings GMAIL says to use:
11
10768
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 a remote IMAP/POP3 server so that I can connect and fetch mail for the user. (Ultimately, I don't want users to have to know what the IMAP/POP3 server name / port is .... I would like to auto-detect all of that). At first I thought I could use...
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9881
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7256
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5943
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.