Changeset 404


Ignore:
Timestamp:
Jun 3, 2020, 10:17:18 AM (4 years ago)
Author:
Rick van der Zwet
Message:

foomailer: Convert to python3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • foomailer/foomail.py

    r402 r404  
    88import time
    99from time import gmtime,strftime
    10 from email.MIMEMultipart import MIMEMultipart
    11 from email.MIMEBase import MIMEBase
    12 from email.MIMEText import MIMEText
    13 from email.Utils import COMMASPACE, formatdate
    14 from email import Encoders
     10from email.mime.multipart import MIMEMultipart
     11from email.mime.base import MIMEBase
     12from email.mime.text import MIMEText
     13from email.utils import COMMASPACE, formatdate
     14from email import encoders
    1515
    1616__svnversion__ = "$Id: foomail.py 633 2008-06-12 19:29:56Z rick $"
     
    1919
    2020def usage():
    21     print "usage %s -f <from> -r <recipient> -s <server> [--spam]" % sys.argv[0]
    22     print "[--virus] [--file <size in kB>] [--message <file>]"
    23     print "[--subject <string>] [--to <string>] [--cc <string>]"
    24     print "[--force]"
     21    print("usage %s -f <from> -r <recipient> -s <server> [--spam]" % sys.argv[0])
     22    print("[--virus] [--file <size in kB>] [--message <file>]")
     23    print("[--subject <string>] [--to <string>] [--cc <string>]")
     24    print("[--force]")
    2525
    2626default_domain = 'example.com'
     
    9191error = False
    9292if not sender:
    93     print "No sender defined"
     93    print("No sender defined")
    9494    error = True
    9595elif not recipient:
    96     print "No recipient defined"
     96    print("No recipient defined")
    9797    error = True
    9898elif not server:
    99     print "No server defined"
     99    print("No server defined")
    100100    error = True
    101101
     
    128128email['X-Port'] = port
    129129email['X-Hostname'] = hostname
    130 email['Message-ID' ] = '<' +''.join(random.sample(string.letters +
     130email['Message-ID' ] = '<' +''.join(random.sample(string.ascii_letters +
    131131                       string.digits,10)) + '@' + email['X-Hostname'] + '>'
    132132email['Date'] = strftime('%a, %d %b %Y %T %z',gmtime())
     
    156156Technical details:\n''' % email
    157157   
    158     for k in email.keys():
     158    for k in list(email.keys()):
    159159        v = email[k]
    160160        msg += "* %-15s : %s\n" % (k,v)
     
    183183    part = MIMEBase('application', "octet-stream")
    184184    part.set_payload('X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*')
    185     Encoders.encode_base64(part)
     185    encoders.encode_base64(part)
    186186    part.add_header('Content-Disposition', 'attachment; filename="eicar.txt"')
    187187    email.attach(part)
     
    194194        part.set_payload(f.read())
    195195        f.close()
    196         Encoders.encode_base64(part)
     196        encoders.encode_base64(part)
    197197        part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file))
    198198        email.attach(part)
    199199
    200 print email.as_string()
     200print(email.as_string())
    201201
    202202if not dry:
     
    208208    server.sendmail(sender, recipient, email.as_string())
    209209    server.quit()
    210     print "Sending took sec: %.2f" % (time.time() - mark)
     210    print("Sending took sec: %.2f" % (time.time() - mark))
Note: See TracChangeset for help on using the changeset viewer.