Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
SMTPChannel Class Reference
Inheritance diagram for SMTPChannel:
async_chat dispatcher

Public Member Functions

def __init__
 
def push
 
def collect_incoming_data
 
def found_terminator
 
def smtp_HELO
 
def smtp_NOOP
 
def smtp_QUIT
 
def smtp_MAIL
 
def smtp_RCPT
 
def smtp_RSET
 
def smtp_DATA
 
- Public Member Functions inherited from async_chat
def __init__
 
def set_terminator
 
def get_terminator
 
def handle_read
 
def handle_write
 
def handle_close
 
def push
 
def push_with_producer
 
def readable
 
def writable
 
def close_when_done
 
def refill_buffer
 
def initiate_send
 
def discard_buffers
 
- Public Member Functions inherited from dispatcher
def __init__
 
def __repr__
 
def add_channel
 
def del_channel
 
def create_socket
 
def set_socket
 

Static Public Attributes

int COMMAND = 0
 
int DATA = 1
 
- Static Public Attributes inherited from async_chat
int ac_in_buffer_size = 4096
 
int ac_out_buffer_size = 4096
 
- Static Public Attributes inherited from dispatcher
int debug = 0
 
int connected = 0
 
int accepting = 0
 
int closing = 0
 
 addr = None
 

Additional Inherited Members

- Data Fields inherited from async_chat
 ac_in_buffer
 
 ac_out_buffer
 
 producer_fifo
 
 terminator
 

Detailed Description

Definition at line 108 of file smtpd.py.

Constructor & Destructor Documentation

def __init__ (   self,
  server,
  conn,
  addr 
)

Definition at line 112 of file smtpd.py.

References SMTPChannel.__addr, SMTPChannel.__conn, SMTPChannel.__data, _Printer.__data, SMTPChannel.__fqdn, SMTPChannel.__greeting, async_chat.__init__(), SMTPChannel.__line, SMTPChannel.__mailfrom, SMTPChannel.__peer, SMTPChannel.__rcpttos, SMTPChannel.__server, SMTPChannel.__state, HTTPConnection.__state, SMTPChannel.COMMAND, socket.getfqdn(), async_chat.push(), and async_chat.set_terminator().

113  def __init__(self, server, conn, addr):
114  asynchat.async_chat.__init__(self, conn)
115  self.__server = server
116  self.__conn = conn
117  self.__addr = addr
118  self.__line = []
119  self.__state = self.COMMAND
120  self.__greeting = 0
121  self.__mailfrom = None
122  self.__rcpttos = []
123  self.__data = ''
124  self.__fqdn = socket.getfqdn()
125  self.__peer = conn.getpeername()
126  print >> DEBUGSTREAM, 'Peer:', repr(self.__peer)
127  self.push('220 %s %s' % (self.__fqdn, __version__))
128  self.set_terminator('\r\n')

Member Function Documentation

def collect_incoming_data (   self,
  data 
)

Definition at line 134 of file smtpd.py.

135  def collect_incoming_data(self, data):
136  self.__line.append(data)
def found_terminator (   self)

Definition at line 138 of file smtpd.py.

References SMTPChannel.__data, _Printer.__data, SMTPChannel.__line, SMTPChannel.__mailfrom, SMTPChannel.__peer, SMTPChannel.__rcpttos, SMTPChannel.__state, HTTPConnection.__state, SMTPChannel.COMMAND, SMTPChannel.DATA, async_chat.push(), async_chat.set_terminator(), string.strip(), and string.upper().

139  def found_terminator(self):
140  line = EMPTYSTRING.join(self.__line)
141  print >> DEBUGSTREAM, 'Data:', repr(line)
142  self.__line = []
143  if self.__state == self.COMMAND:
144  if not line:
145  self.push('500 Error: bad syntax')
146  return
147  method = None
148  i = line.find(' ')
149  if i < 0:
150  command = line.upper()
151  arg = None
152  else:
153  command = line[:i].upper()
154  arg = line[i+1:].strip()
155  method = getattr(self, 'smtp_' + command, None)
156  if not method:
157  self.push('502 Error: command "%s" not implemented' % command)
158  return
159  method(arg)
160  return
161  else:
162  if self.__state != self.DATA:
163  self.push('451 Internal confusion')
164  return
165  # Remove extraneous carriage returns and de-transparency according
166  # to RFC 821, Section 4.5.2.
167  data = []
168  for text in line.split('\r\n'):
169  if text and text[0] == '.':
170  data.append(text[1:])
171  else:
172  data.append(text)
173  self.__data = NEWLINE.join(data)
174  status = self.__server.process_message(self.__peer,
175  self.__mailfrom,
176  self.__rcpttos,
177  self.__data)
178  self.__rcpttos = []
179  self.__mailfrom = None
180  self.__state = self.COMMAND
181  self.set_terminator('\r\n')
182  if not status:
183  self.push('250 Ok')
184  else:
185  self.push(status)
def push (   self,
  msg 
)

Definition at line 130 of file smtpd.py.

References async_chat.push().

131  def push(self, msg):
132  asynchat.async_chat.push(self, msg + '\r\n')
def smtp_DATA (   self,
  arg 
)

Definition at line 262 of file smtpd.py.

References SMTPChannel.__rcpttos, SMTPChannel.__state, HTTPConnection.__state, SMTPChannel.DATA, async_chat.push(), and async_chat.set_terminator().

263  def smtp_DATA(self, arg):
264  if not self.__rcpttos:
265  self.push('503 Error: need RCPT command')
266  return
267  if arg:
268  self.push('501 Syntax: DATA')
269  return
270  self.__state = self.DATA
271  self.set_terminator('\r\n.\r\n')
272  self.push('354 End data with <CR><LF>.<CR><LF>')
273 
274 
def smtp_HELO (   self,
  arg 
)

Definition at line 187 of file smtpd.py.

References SMTPChannel.__fqdn, SMTPChannel.__greeting, and async_chat.push().

188  def smtp_HELO(self, arg):
189  if not arg:
190  self.push('501 Syntax: HELO hostname')
191  return
192  if self.__greeting:
193  self.push('503 Duplicate HELO/EHLO')
194  else:
195  self.__greeting = arg
196  self.push('250 %s' % self.__fqdn)
def smtp_MAIL (   self,
  arg 
)

Definition at line 222 of file smtpd.py.

References SMTPChannel.__getaddr(), SMTPChannel.__mailfrom, and async_chat.push().

223  def smtp_MAIL(self, arg):
224  print >> DEBUGSTREAM, '===> MAIL', arg
225  address = self.__getaddr('FROM:', arg)
226  if not address:
227  self.push('501 Syntax: MAIL FROM:<address>')
228  return
229  if self.__mailfrom:
230  self.push('503 Error: nested MAIL command')
231  return
232  self.__mailfrom = address
233  print >> DEBUGSTREAM, 'sender:', self.__mailfrom
234  self.push('250 Ok')
def smtp_NOOP (   self,
  arg 
)

Definition at line 197 of file smtpd.py.

References async_chat.push().

198  def smtp_NOOP(self, arg):
199  if arg:
200  self.push('501 Syntax: NOOP')
201  else:
202  self.push('250 Ok')
def smtp_QUIT (   self,
  arg 
)

Definition at line 203 of file smtpd.py.

References async_chat.close_when_done(), async_chat.push(), string.strip(), and string.upper().

204  def smtp_QUIT(self, arg):
205  # args is ignored
206  self.push('221 Bye')
207  self.close_when_done()
def smtp_RCPT (   self,
  arg 
)

Definition at line 235 of file smtpd.py.

References SMTPChannel.__getaddr(), SMTPChannel.__mailfrom, SMTPChannel.__rcpttos, and async_chat.push().

236  def smtp_RCPT(self, arg):
237  print >> DEBUGSTREAM, '===> RCPT', arg
238  if not self.__mailfrom:
239  self.push('503 Error: need MAIL command')
240  return
241  address = self.__getaddr('TO:', arg)
242  if not address:
243  self.push('501 Syntax: RCPT TO: <address>')
244  return
245  if address.lower().startswith('stimpy'):
246  self.push('503 You suck %s' % address)
247  return
248  self.__rcpttos.append(address)
249  print >> DEBUGSTREAM, 'recips:', self.__rcpttos
250  self.push('250 Ok')
def smtp_RSET (   self,
  arg 
)

Definition at line 251 of file smtpd.py.

References SMTPChannel.__data, _Printer.__data, SMTPChannel.__mailfrom, SMTPChannel.__rcpttos, SMTPChannel.__state, HTTPConnection.__state, SMTPChannel.COMMAND, and async_chat.push().

252  def smtp_RSET(self, arg):
253  if arg:
254  self.push('501 Syntax: RSET')
255  return
256  # Resets the sender, recipients, and data, but not the greeting
257  self.__mailfrom = None
258  self.__rcpttos = []
259  self.__data = ''
260  self.__state = self.COMMAND
261  self.push('250 Ok')

Field Documentation

int COMMAND = 0
static

Definition at line 109 of file smtpd.py.

int DATA = 1
static

Definition at line 110 of file smtpd.py.


The documentation for this class was generated from the following file: