473,385 Members | 1,588 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,385 software developers and data experts.

copying or moving the mail message using imaplib

Hi Friends,

I am doing project in python.I am new to this. My problem
is I want to move the mail message to other folder in the mail using
imaplib (E.g) I want to move a message from the inbox to the Draft
folder in my account using python code. Can any one help me by giving a
sample code to do this?
Thanks in advance

Jul 18 '05 #1
4 7061
Thanks for ur message .How it is possible to copy the messages betwwen
folder ?I can't understand the copy function in python documentation.
Please Can u give me a sample example for this. And I also to copy
using uid but in vain. here is my program.

#!/usr/bin/env python
#Normal Library
import socket
import os
import re
import time
import sys
import getopt
import types
import traceback
import email
import mhlib,popen2
import string, random
import StringIO, rfc822

import email.Parser
from getpass import getpass
from email.Header import Header
from email.Utils import parsedate
from imaplib import IMAP4 as BaseIMAP
from email.Message import Message
from email.Header import Header
# Antispam database lib
class IMAPSession(BaseIMAP):

def __init__(self, server, port, debug=0, do_expunge=False):

BaseIMAP.__init__(self, server, port)

def getsizes(imap, msgs):
uidfetchbatchsize =25
res2=[]

# Python really needs do - while
while 1:
if len(msgs)==0: break
if len(msgs)>uidfetchbatchsize:
msgmore=msgs[uidfetchbatchsize:]
msgs=msgs[:uidfetchbatchsize]
else:
msgmore=[]
msgs=string.join(msgs, ',')
res=imap.uid("FETCH", msgs, "(UID RFC822.SIZE)")
assertok(res, "uid fetch", msgs, "(UID RFC822.SIZE)")
for i in res[1]:
mo=gsre.match(i)
if mo is None:
if verbose: print "getsize Eh?", i
else:
res2.append((mo.group(2), mo.group(1)))
msgs=msgmore
return res2


def run():
import getpass
#name = raw_input("Enter User name : ")
passwd = getpass.getpass ("Enter the password : ")
server ="mail.myhost.com"
port = 143
ss = IMAPSession(server,port)
sd = ss.login ("raghul",passwd)
uidfetchbatchsize =25
print ss.list()
print ss.select('Junk E-mail')
typ, data = ss.search(None,"ALL" )
for num in data[0].split():
typ, data = ss.fetch(num, '(RFC822)')
print 'Message %s\n%s\n' % (num, data[0][1])
print "_____"
dat = ss.uid('copy',num,'INBOX')
print "copied"
print dat
print num
print "_____"
ss.logout()



if __name__ == '__main__':
run()

Jul 18 '05 #2
On 2005-02-22, Raghul <ra*****@gmail.com> wrote:
Thanks for ur message .How it is possible to copy the messages betwwen
folder ?I can't understand the copy function in python documentation.


Maybe you should take a look at the RFC for IMAP4:

http://www.faqs.org/rfcs/rfc2060.html

The UID command is documented in section 6.4.8. It looks
fairly clear to me.

--
Grant Edwards grante Yow! Mr and Mrs PED, can
at I borrow 26.7
visi.com
Jul 18 '05 #3
Thanx I got some clear view about this. In the above program I used uid
method to copy thje mail to "Inbox".This shows the out put of my mail
messages and In the copy of messages I got the output
when printing the "dat"

('OK', [None])
('OK', ['2 (UID 16 FLAGS (\\Seen))'])
2

I cannot see the message in the INBOX. Can anyone give me a solution.

Jul 18 '05 #4
Thanx I got some clear view about this. In the above program I used uid
method to copy thje mail to "Inbox".This shows the out put of my mail
messages and In the copy of messages I got the output
when printing the "dat"

('OK', [None])
('OK', ['2 (UID 16 FLAGS (\\Seen))'])
2

I cannot see the message in the INBOX. Can anyone give me a solution.

Jul 18 '05 #5

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

Similar topics

2
by: Bill Sneddon | last post by:
Anyone have an example they are willing to share that shows how to use the store command in imaplib? store( message_set, command, flag_list) Alters flag dispositions for messages in mailbox. ...
1
by: Wilfredo Sanchez | last post by:
The docs for imaplib are pretty scant, and i guess the library is meant for people who already know IMAP well and want low-level access to the protocol, as opposed to someone who wants "get me the...
1
by: Colin Brown | last post by:
The Python 2.3 documentation in imaplib says: Internaldate2tuple( datestr) Converts an IMAP4 INTERNALDATE string to Coordinated Universal Time. Returns a time module tuple. Time2Internaldate(...
0
by: Wolfgang Kohnen | last post by:
Hello out there! I am new to python and so far I like it a lot. Now I want to create some IMAP mailboxes on my cyrus imapd, with quotas and each user should be subscribed to her/his own spam...
6
by: Hemant Shah | last post by:
Folks, I need to move HOME directory of an instance to another directory. What is the best way of doing it? Is changing password file enough? or dies DB2 store this info in it's own config? ...
4
by: Andy Hutchings | last post by:
Hi everybody - hope you can help out here. I have a form in a database, which is a columnar form from one of the tables in the db - there is a sub-form to the form which is a datasheet view of...
1
by: csselo | last post by:
Hi I am looking for a code sample which searches mail by date with imaplib example: get email from 01.01.2007 to now how can I change imaplib search parameters?
0
by: Igor V. Rafienko | last post by:
Hi, I was wondering if anyone had a suggestion for the following issue. I would like to talk to an IMAP-server, imaplib being the tool of choice, of course. Unfortunately it may happen that...
3
by: KeefTM | last post by:
Hello, I am getting an odd error when trying to establish an IMAP connection: File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/ imaplib.py", line 904, in _get_response...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.