MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / smtpDeliver

Class smtpDeliver

src/class_smtpDeliver.py:16–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14SMTPDOMAIN = "bmaddr.lan"
15
16class smtpDeliver(threading.Thread, StoppableThread):
17 _instance = None
18
19 def __init__(self, parent=None):
20 threading.Thread.__init__(self, name="smtpDeliver")
21 self.initStop()
22
23 def stopThread(self):
24 try:
25 queues.UISignallerQueue.put(("stopThread", "data"))
26 except:
27 pass
28 super(smtpDeliver, self).stopThread()
29
30 @classmethod
31 def get(cls):
32 if not cls._instance:
33 cls._instance = smtpDeliver()
34 return cls._instance
35
36 def run(self):
37 while state.shutdown == 0:
38 command, data = queues.UISignalQueue.get()
39 if command == 'writeNewAddressToTable':
40 label, address, streamNumber = data
41 pass
42 elif command == 'updateStatusBar':
43 pass
44 elif command == 'updateSentItemStatusByToAddress':
45 toAddress, message = data
46 pass
47 elif command == 'updateSentItemStatusByAckdata':
48 ackData, message = data
49 pass
50 elif command == 'displayNewInboxMessage':
51 inventoryHash, toAddress, fromAddress, subject, body = data
52 dest = BMConfigParser().safeGet("bitmessagesettings", "smtpdeliver", '')
53 if dest == '':
54 continue
55 try:
56 u = urlparse.urlparse(dest)
57 to = urlparse.parse_qs(u.query)['to']
58 client = smtplib.SMTP(u.hostname, u.port)
59 msg = MIMEText(body, 'plain', 'utf-8')
60 msg['Subject'] = Header(subject, 'utf-8')
61 msg['From'] = fromAddress + '@' + SMTPDOMAIN
62 toLabel = map (lambda y: BMConfigParser().safeGet(y, "label"), filter(lambda x: x == toAddress, BMConfigParser().addresses()))
63 if len(toLabel) > 0:
64 msg['To'] = "\"%s\" <%s>" % (Header(toLabel[0], 'utf-8'), toAddress + '@' + SMTPDOMAIN)
65 else:
66 msg['To'] = toAddress + '@' + SMTPDOMAIN
67 client.ehlo()
68 client.starttls()
69 client.ehlo()
70 client.sendmail(msg['From'], [to], msg.as_string())
71 logger.info("Delivered via SMTP to %s through %s:%i ...", to, u.hostname, u.port)
72 client.quit()
73 except:

Callers 2

startMethod · 0.90
getMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected