mirror of
https://github.com/Mailu/Mailu.git
synced 2025-01-14 02:34:22 +02:00
Rewrite of email test script and added eicar virus file
This commit is contained in:
parent
4032e7128d
commit
76d9fc3865
@ -1 +1,6 @@
|
||||
python3 tests/email_test.py message-filters
|
||||
python3 tests/email_test.py message-virus "tests/compose/filters/eicar.com"
|
||||
if [ $? -eq 99 ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
1
tests/compose/filters/eicar.com
Normal file
1
tests/compose/filters/eicar.com
Normal file
@ -0,0 +1 @@
|
||||
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
|
@ -2,46 +2,58 @@ import smtplib
|
||||
import imaplib
|
||||
import time
|
||||
import sys
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
import ntpath
|
||||
from email.mime.base import MIMEBase
|
||||
from email import encoders
|
||||
|
||||
email_msg = sys.argv[1]
|
||||
msg = MIMEMultipart()
|
||||
msg['From'] = "admin@mailu.io"
|
||||
msg['To'] = "user@mailu.io"
|
||||
msg['Subject'] = "File Test"
|
||||
msg.attach(MIMEText(sys.argv[1], 'plain'))
|
||||
|
||||
#Login to smt server and sending email with secret message
|
||||
def send_email(msg):
|
||||
print("Sending email ...")
|
||||
server = smtplib.SMTP('localhost')
|
||||
server.set_debuglevel(1)
|
||||
server.connect('localhost', 587)
|
||||
server.ehlo()
|
||||
server.starttls()
|
||||
server.ehlo()
|
||||
server.login("admin@mailu.io", "password")
|
||||
|
||||
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
|
||||
server.quit()
|
||||
if len(sys.argv) == 3:
|
||||
part = MIMEBase('application', 'octet-stream')
|
||||
part.set_payload((open(sys.argv[2], "rb")).read())
|
||||
encoders.encode_base64(part)
|
||||
part.add_header('Content-Disposition', "attachment; filename=%s" % ntpath.basename(sys.argv[2]))
|
||||
msg.attach(part)
|
||||
|
||||
print("email sent with message " + msg)
|
||||
try:
|
||||
smtp_server = smtplib.SMTP('localhost')
|
||||
smtp_server.set_debuglevel(1)
|
||||
smtp_server.connect('localhost', 587)
|
||||
smtp_server.ehlo()
|
||||
smtp_server.starttls()
|
||||
smtp_server.ehlo()
|
||||
smtp_server.login("admin@mailu.io", "password")
|
||||
|
||||
smtp_server.sendmail("admin@mailu.io", "user@mailu.io", msg.as_string())
|
||||
smtp_server.quit()
|
||||
except:
|
||||
sys.exit(25)
|
||||
|
||||
#Login to imap server, read latest email and check for secret message
|
||||
def read_email():
|
||||
print("Receiving email ...")
|
||||
server = imaplib.IMAP4_SSL('localhost')
|
||||
server.login('user@mailu.io', 'password')
|
||||
|
||||
stat, count = server.select('inbox')
|
||||
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
|
||||
|
||||
print("email received with message " + str(data[0][1]))
|
||||
|
||||
if email_msg in str(data[0][1]):
|
||||
print("Success!")
|
||||
else:
|
||||
print("Failed receiving email with message %s" % email_msg)
|
||||
sys.exit(1)
|
||||
server.close()
|
||||
server.logout()
|
||||
time.sleep(30)
|
||||
|
||||
try:
|
||||
imap_server = imaplib.IMAP4_SSL('localhost')
|
||||
imap_server.login('user@mailu.io', 'password')
|
||||
except:
|
||||
sys.exit(110)
|
||||
|
||||
stat, count = imap_server.select('inbox')
|
||||
try:
|
||||
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
|
||||
except :
|
||||
sys.exit(99)
|
||||
|
||||
if sys.argv[1] in str(data[0][1]):
|
||||
print("Success sending and receiving email!")
|
||||
else:
|
||||
print("Failed receiving email with message %s" % sys.argv[1])
|
||||
sys.exit(99)
|
||||
|
||||
send_email(email_msg)
|
||||
print("Sleeping for 1m")
|
||||
time.sleep(60)
|
||||
read_email()
|
||||
imap_server.close()
|
||||
imap_server.logout()
|
||||
|
Loading…
Reference in New Issue
Block a user