added checks and mail delete to imapy
This commit is contained in:
40
imapy.py
40
imapy.py
@@ -8,8 +8,10 @@ from configparser import ConfigParser
|
|||||||
from cursesmenu import *
|
from cursesmenu import *
|
||||||
from cursesmenu.items import *
|
from cursesmenu.items import *
|
||||||
import dialog
|
import dialog
|
||||||
config_file_path=os.path.join(os.path.expanduser('~'),"imap_virus_marvin.ini")
|
config_file_path=os.path.join(os.path.expanduser('~'),".imap_virus_marvin.ini")
|
||||||
dialog=dialog.Dialog()
|
dialog=dialog.Dialog()
|
||||||
|
# dialog.set_background_title("IMAP-Mail-Renamer")
|
||||||
|
marvin_pattern=re.compile('MARVIN#\d{14}_')
|
||||||
|
|
||||||
def edit(num):
|
def edit(num):
|
||||||
pass
|
pass
|
||||||
@@ -101,34 +103,27 @@ def search_mails(key,value):
|
|||||||
def print_mail(num):
|
def print_mail(num):
|
||||||
eml=get_mail(num)
|
eml=get_mail(num)
|
||||||
dialogit(str(eml))
|
dialogit(str(eml))
|
||||||
# dialogit(eml['Subject'])
|
|
||||||
|
|
||||||
def edit_mail(num):
|
def edit_mail(num):
|
||||||
global im
|
global im
|
||||||
global config
|
global config
|
||||||
eml=get_mail(num)
|
eml=get_mail(num)
|
||||||
a,b=dialog.inputbox("Edit Subject",init=eml['Subject'])
|
old_subject=eml['Subject']
|
||||||
eml.replace_header('Subject',b)
|
action,new_subject=dialog.inputbox("Edit Subject",init=old_subject)
|
||||||
# dialogit(str(eml))
|
if action == "OK":
|
||||||
# c.append('INBOX', '', imaplib.Time2Internaldate(time.time()), str(new_message))
|
eml.replace_header('Subject',new_subject)
|
||||||
print(type(str(eml)))
|
# c.append('INBOX', '', imaplib.Time2Internaldate(time.time()), str(new_message))
|
||||||
c,d = im.append('INBOX','', imaplib.Time2Internaldate(time.time()),str(eml).encode('utf-8'))
|
c,d = im.append('INBOX','', imaplib.Time2Internaldate(time.time()),str(eml).encode('utf-8'))
|
||||||
print(c)
|
# c= OK
|
||||||
print(d)
|
# d= [b'[APPENDUID 1252405521 2655] APPEND Ok.']
|
||||||
# c= OK
|
# if append ok delete original mailbox
|
||||||
# d= [b'[APPENDUID 1252405521 2655] APPEND Ok.']
|
if "OK" in c:
|
||||||
# if append ok delete original mailbox
|
delete_mail(num)
|
||||||
# delete mail
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def quit():
|
def quit():
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
def dialogit(text):
|
def dialogit(text):
|
||||||
# d.msgbox(text)
|
|
||||||
dialog.scrollbox(text,height=60,width=110)
|
dialog.scrollbox(text,height=60,width=110)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -145,14 +140,9 @@ def main():
|
|||||||
typ, nums = im.search(None, 'ALL')
|
typ, nums = im.search(None, 'ALL')
|
||||||
for n in nums[0].split():
|
for n in nums[0].split():
|
||||||
subject_line=get_subject(n)
|
subject_line=get_subject(n)
|
||||||
if not "MARVIN" in subject_line:
|
if not marvin_pattern.match(subject_line):
|
||||||
function_item = FunctionItem(subject_line, edit_mail , [n] ,should_exit=True)
|
function_item = FunctionItem(subject_line, edit_mail , [n] ,should_exit=True)
|
||||||
menu.append_item(function_item)
|
menu.append_item(function_item)
|
||||||
|
|
||||||
# print(subject_line)
|
|
||||||
# m=get_mail(n)
|
|
||||||
# print(m.)
|
|
||||||
# menu.append_item(FunctionItem("QUIT",quit,should_exit=True))
|
|
||||||
returnval=menu.show()
|
returnval=menu.show()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user