copying or moving the mail message using imaplib

R

Raghul

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
 
R

Raghul

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()
 
R

Raghul

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.
 
R

Raghul

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top