updated imapy
This commit is contained in:
33
imapy.py
33
imapy.py
@@ -63,26 +63,51 @@ def decode(data):
|
|||||||
res+= part[0].decode(part[1])
|
res+= part[0].decode(part[1])
|
||||||
return "".join(res.split())
|
return "".join(res.split())
|
||||||
|
|
||||||
def get_subject(num,imap):
|
def get_subject(num):
|
||||||
res, data = imap.fetch(num,'BODY.PEEK[HEADER.FIELDS (SUBJECT)]')
|
global im
|
||||||
|
res, data = im.fetch(num,'BODY.PEEK[HEADER.FIELDS (SUBJECT)]')
|
||||||
x,y = data[0]
|
x,y = data[0]
|
||||||
y=force_decode(y)
|
y=force_decode(y)
|
||||||
y=y[9:]
|
y=y[9:]
|
||||||
return decode(y)
|
return decode(y)
|
||||||
|
|
||||||
|
def get_mail(num):
|
||||||
|
global im
|
||||||
|
_,data = im.fetch(num,'(RFC822)')
|
||||||
|
eml=email.message_from_bytes(data[0][1])
|
||||||
|
return eml
|
||||||
|
|
||||||
|
def delete_mail(num):
|
||||||
|
global im
|
||||||
|
im.store(num, '+FLAGS', '\\Deleted')
|
||||||
|
im.expunge()
|
||||||
|
|
||||||
|
def search_mails(key,value):
|
||||||
|
global im
|
||||||
|
_, nums = im.search(None,key,'"{}"'.format(value))
|
||||||
|
return nums[0].split():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
global config
|
||||||
|
global im
|
||||||
config=get_config()
|
config=get_config()
|
||||||
im=imaplib.IMAP4_SSL(config["SERVER"]["host"],config["SERVER"]["port"])
|
im=imaplib.IMAP4_SSL(config["SERVER"]["host"],config["SERVER"]["port"])
|
||||||
# im=imaplib.IMAP4_SSL(imap_url,imap_port)
|
|
||||||
im.login(config["CREDENTIALS"]["username"],config["CREDENTIALS"]["password"])
|
im.login(config["CREDENTIALS"]["username"],config["CREDENTIALS"]["password"])
|
||||||
im.select(config["SERVER"]["mailbox"])
|
im.select(config["SERVER"]["mailbox"])
|
||||||
|
|
||||||
|
|
||||||
typ, nums = im.search(None, 'ALL')
|
typ, nums = im.search(None, 'ALL')
|
||||||
for n in nums[0].split():
|
for n in nums[0].split():
|
||||||
print(get_subject(n, im))
|
subject_line=get_subject(n)
|
||||||
|
if not "MARVIN" in subject_line:
|
||||||
|
print(subject_line)
|
||||||
|
m=get_mail(n)
|
||||||
|
# print(m.)
|
||||||
|
|
||||||
im.close()
|
im.close()
|
||||||
im.logout()
|
im.logout()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user