Commit d61bc920 authored by Jeffrey Shell's avatar Jeffrey Shell

Further SMTP and socket improvements

parent fd6b90e4
from Globals import Persistent, HTMLFile, HTML, MessageDialog from Globals import Persistent, HTMLFile, HTML, MessageDialog
from socket import * from socket import *; from select import select
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
import Acquisition, sys, regex, string, types import Acquisition, sys, regex, string, types
import OFS.SimpleItem import OFS.SimpleItem
#$Id: MailHost.py,v 1.12 1997/09/16 18:15:17 jeffrey Exp $ #$Id: MailHost.py,v 1.13 1997/09/17 15:40:09 jeffrey Exp $
__version__ = "$Revision: 1.12 $"[11:-2] __version__ = "$Revision: 1.13 $"[11:-2]
smtpError = "SMTP Error" smtpError = "SMTP Error"
MailHostError = "MailHost Error" MailHostError = "MailHost Error"
...@@ -102,9 +102,10 @@ class SendMail: ...@@ -102,9 +102,10 @@ class SendMail:
def __init__(self, smtpHost, smtpPort, localHost="localhost"): def __init__(self, smtpHost, smtpPort, localHost="localhost"):
self.conn = socket(AF_INET, SOCK_STREAM) self.conn = socket(AF_INET, SOCK_STREAM)
self.conn.connect(smtpHost, smtpPort) self.conn.connect(smtpHost, smtpPort)
self.fd=self.conn.fileno()
self.conn.send("helo "+localHost+"\r\n") self.conn.send("helo "+localHost+"\r\n")
self._check('220') while 1:
self.getLine() #extra lines for some servers if not self._check(): break
def __del__(self): def __del__(self):
self._close() self._close()
...@@ -112,6 +113,8 @@ class SendMail: ...@@ -112,6 +113,8 @@ class SendMail:
def getLine(self): def getLine(self):
line='' line=''
while 1: while 1:
if not select([self.fd],[],[],1.0)[0]:
break
data=self.conn.recv(1) data=self.conn.recv(1)
if (not data) or (data == '\n'): if (not data) or (data == '\n'):
break break
...@@ -120,6 +123,7 @@ class SendMail: ...@@ -120,6 +123,7 @@ class SendMail:
def _check(self, lev='250'): def _check(self, lev='250'):
line = self.getLine() line = self.getLine()
if not line: return 0 #can't check an empty line, eh?
try: try:
code=string.atoi(line[:3]) code=string.atoi(line[:3])
except: except:
...@@ -127,7 +131,9 @@ class SendMail: ...@@ -127,7 +131,9 @@ class SendMail:
if code > 500: if code > 500:
#raise smtpError, "Expected %s, got %s from SMTP" % (lev, data[:3]) #raise smtpError, "Expected %s, got %s from SMTP" % (lev, data[:3])
raise smtpError, "Recieved error code %s from SMTP: %s" % (code, line) raise smtpError, "Recieved error code %s from SMTP: %s"\
% (code, line)
return 1
def send(self, mfrom, mto, subj, body): def send(self, mfrom, mto, subj, body):
self.conn.send("mail from:<%s>\n"%mfrom) self.conn.send("mail from:<%s>\n"%mfrom)
...@@ -183,6 +189,9 @@ def decapitate(message, **kw): ...@@ -183,6 +189,9 @@ def decapitate(message, **kw):
#$Log: MailHost.py,v $ #$Log: MailHost.py,v $
#Revision 1.13 1997/09/17 15:40:09 jeffrey
#Further SMTP and socket improvements
#
#Revision 1.12 1997/09/16 18:15:17 jeffrey #Revision 1.12 1997/09/16 18:15:17 jeffrey
#Further SMTP updates... #Further SMTP updates...
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment