def queue(self, transaction): log.info('forwarding to %s:%d', self.smtp_server, self.smtp_port) smtp = smtplib.SMTP(self.smtp_server, self.smtp_port) code, msg = smtp.mail(str(transaction.sender or '')) if code != 250: raise DenyError(msg) for rcpt in transaction.recipients: code, msg = smtp.rcpt(str(rcpt)) if code != 250: raise DenyError(msg) code, msg = smtp.docmd('data') if code != 354: raise smtplib.SMTPDataError(code, msg) msg = transaction.body header = smtplib.quotedata(msg.headers.as_string()) smtp.send(header) msg.seek(msg.body_start) for line in msg: smtp.send(smtplib.quotedata(line)) smtp.send(smtplib.CRLF + '.' + smtplib.CRLF) code, msg = smtp.getreply() if code != 250: raise DenyError(msg) code, msg = smtp.quit() log.info('finished queueing') return True
def data(self, msg): self.putcmd("data") (code,repl)=self.getreply() if self.debuglevel >0 : print>>stderr, "data:", (code,repl) if code != 354: raise SMTPDataError(code,repl) else: q = quotedata(msg) if q[-2:] != CRLF: q = q + CRLF q = q + "." + CRLF # begin modified send code chunk_size = 2048 bytes_sent = 0 while bytes_sent != len(q): chunk = q[bytes_sent:bytes_sent+chunk_size] self.send(chunk) bytes_sent += len(chunk) if hasattr(self, "callback"): self.callback(bytes_sent, len(q)) # end modified send code (code,msg)=self.getreply() if self.debuglevel >0 : print>>stderr, "data:", (code,msg) return (code,msg)
def data(self, msg): self.putcmd("data") (code, repl) = self.getreply() if self.debuglevel > 0: print >> stderr, "data:", (code, repl) if code != 354: raise SMTPDataError(code, repl) else: q = quotedata(msg) if q[-2:] != CRLF: q = q + CRLF q = q + "." + CRLF # begin modified send code chunk_size = 2048 bytes_sent = 0 while bytes_sent != len(q): chunk = q[bytes_sent:bytes_sent + chunk_size] self.send(chunk) bytes_sent += len(chunk) if hasattr(self, "callback"): self.callback(bytes_sent, len(q)) # end modified send code (code, msg) = self.getreply() if self.debuglevel > 0: print>> stderr, "data:", (code, msg) return (code, msg)
def data(self,msg): """ This is a modified copy of smtplib.SMTP.data() Sending data in chunks and calling self.callback to keep track of progress, """ self.putcmd("data") (code,repl)=self.getreply() if self.debuglevel >0 : print>>stderr, "data:", (code,repl) if code != 354: raise SMTPDataError(code,repl) else: q = quotedata(msg) if q[-2:] != CRLF: q = q + CRLF q = q + "." + CRLF # begin modified send code chunk_size = 2048 bytes_sent = 0 while bytes_sent != len(q): chunk = q[bytes_sent:bytes_sent+chunk_size] self.send(chunk) bytes_sent += len(chunk) if hasattr(self, "callback"): self.callback(bytes_sent, len(q)) # end modified send code (code,msg)=self.getreply() if self.debuglevel >0 : print>>stderr, "data:", (code,msg) return (code,msg)
def data(self, msg): """ SMTP 'DATA' command -- sends message data to server. Automatically quotes lines beginning with a period per rfc821. Raises SMTPDataError if there is an unexpected reply to the DATA command; the return value from this method is the final response code received when the all data is sent. msg: Message in a string buffer or a filename referring to a file containin the data to be send (string). Returns: Tuple with the status code + a message from the SMTP host (tuple/integer, string). """ self.putcmd("data") (code, repl) = self.getreply() if self.debuglevel > 0: print("data:", (code, repl)) if code != 354: raise smtplib.SMTPDataError(code, repl) else: if (not self.__msgInFile): # Data contained in the message in memory. q = smtplib.quotedata(msg) if q[-2:] != smtplib.CRLF: q = q + smtplib.CRLF q = q + "." + smtplib.CRLF self.send(q) else: # Data to send is contained in a file. fo = open(msg) while (1): buf = fo.read(16384) if (buf == ""): break qBuf = smtplib.quotedata(buf) self.send(buf) fo.close() self.send(smtplib.CRLF + "." + smtplib.CRLF) (code, msg) = self.getreply() if (self.debuglevel > 0): print("data:", (code, msg)) return (code, msg)
def data(self,msg): """SMTP 'DATA' command -- sends message data to server. Automatically quotes lines beginning with a period per rfc821. Raises SMTPDataError if there is an unexpected reply to the DATA command; the return value from this method is the final response code received when the all data is sent. """ self.putcmd("data") (code,repl)=self.getreply() if self.debuglevel >0 : print>>stderr, "data:", (code,repl) if code != 354: raise SMTPDataError(code,repl) else: q = quotedata(msg) if q[-2:] != CRLF: q = q + CRLF q = q + "." + CRLF # begin chunked sent code chunk_size = 2048 bytes_sent = 0 while bytes_sent != len(q): chunk = q[bytes_sent:bytes_sent+chunk_size] self.send(chunk) bytes_sent += len(chunk) if hasattr(self, "callback"): if not self.callback(time(), bytes_sent, len(q)): raise CancelledException # end chunked sent code (code,msg)=self.getreply() if self.debuglevel >0 : print>>stderr, "data:", (code,msg) return (code,msg)
def update_event(self, inp=-1): self.set_output_val(0, smtplib.quotedata(self.input(0)))
def testQuoteData(self): teststr = "abc\n.jkl\rfoo\r\n..blue" expected = "abc\r\n..jkl\r\nfoo\r\n...blue" self.assertEqual(expected, smtplib.quotedata(teststr))
# if data is less than chunk size, check it if len(data) < CHUNKSIZE: connection = spamd.SpamdConnection(spamd_host) connection.addheader('User', recipient) try: connection.check(spamd.PROCESS, data) data = connection.response_message except spamd.error, e: sys.stderr.write('spamcheck: %s' % str(e)) # send the data in chunks lmtp.putcmd("data") code, msg = lmtp.getreply() if code != 354: sys.exit(EX_TEMPFAIL) lmtp.send(smtplib.quotedata(data)) data = sys.stdin.read(CHUNKSIZE) while data != '': lmtp.send(smtplib.quotedata(data)) data = sys.stdin.read(CHUNKSIZE) lmtp.send('\r\n.\r\n') code, msg = lmtp.getreply() if code != 250: sys.exit(EX_TEMPFAIL) def main(argv): spamd_host = '' lmtp_host = None sender = None recipient = None
def _send_line(self, line): data = smtplib.quotedata(line) self.smtp.send(data) return data