Help, re SMTP posting / RFC822

Benjamin Schollnick junkster at nospam.rochester.rr.com
Thu Sep 16 20:24:32 EDT 1999


Folks,

	It looks like I need some more advance Python shoulders to cry on and
ask for
help, again......

	I'm working on some code for a CGI package at work.  Which, by the 
way, I've already been given permission to release here once I'm done.
 I'd like to get some feedback to help improve my python coding.

	But, this is just a small part of it, yet, I've got two doosy of a 
question(s).

1)         def mail_to (self, persons_to_mailto):
		tmp = ''
		tmp = string.splitfields(persons_to_mailto, ',')
		self.to_text = 'To: '
		for count in range(len(tmp)):
#			self.to_text = self.to_text + '<' 
			self.to_text = self.to_text + tmp[count] 
#			self.to_text = self.to_text + '\x3E' 
			self.to_text = self.to_text + '\n'

	See the two commented lines?  I can't get them to work in *ANY* form.
 If I have the < or > character
	in 'em, python just seems to goof up and no value gets placed into 
TO_TEXT.

	I seem to remember the Greater & Less signs having a special 
representation code (i.e. \n) in python but 	can't back it up with 
documentation.  (I looked but couldn't find it).

	I've tried hex representations, CHR(60) / CHR(62), and a few other 
tries to work around this, but haven't 	succeeded.

2) 	I'm confused about using variables from a OBJECT, inside a routine
of said object.  I was able to
	write the entire POP3.PY code without using SELF.<VAR NAME> and ran 
it.  It seemed that certain
	routines needed SELF, and others would seem to work fine w/o the 
self.  Have I used self correctly,
	or horribly misused it?  (See full code below)

3) 	Anyone got any suggestions on making this code "more intuitive" or
better python code?  It's simplistic I 	know, but I'm still getting 
the hang of python and trying to supress my Borland Pascal OOP 
experience(s).

				Thanks in advance,

					- Benjamin

----------- POP3.PY (full) -------
#
#
#
import string

class sendpop3:
        def __init__(self):
                self.to_text         = ''
                self.from_text       = ''
                self.subject_text    = ''
                self.header_text     = ''
                self.body_text       = ''
                self.body_sep        = '\n\n'        
                
        def mail_to (self, persons_to_mailto):
		tmp = ''
		tmp = string.splitfields(persons_to_mailto, ',')
		self.to_text = 'To: '
		for count in range(len(tmp)):
#			self.to_text = self.to_text + '<' 
			self.to_text = self.to_text + tmp[count] 
#			self.to_text = self.to_text + '\x3E' 
			self.to_text = self.to_text + '\n'

        def mail_from (self, persons_who_are_mailing):
#                from_text = 'From: 
'+string.splitfields(persons_who_are_mailing, ',')+ '\n'
		tmp = ''
		tmp = string.splitfields(persons_who_are_mailing, ',')
		self.from_text = 'From: '
		for count in range(len(tmp)):
			self.from_text = self.from_text + tmp[count] + '\n'

	def return_mail_from (self):
		return from_text

	def return_mail_to (self):
		return self.to_text

        def mail_subject (self, subject):
                self.subject_text    = 'Subject: ' + subject+ '\n'

        def start_body_text  (self):
                self.body_text = ''

        def append_body_line (self, bodytext_to_add):
                self.body_text = self.body_text + bodytext_to_add + 
'\n'

        def blankline (self):
                self.body_text = self.body_text + '\n'

        def body_end (self):
                self.body_text = self.body_text + '\n\f.\n\f'
        
        def return_message (self):
		tmp_message = ''
                tmp_message = self.to_text + ' ' +self.from_text + ' '
+self.body_sep + self.to_text + ' ' + self.from_text +  
self.subject_text + self.body_text
                return tmp_message

================================
Please feel free to copy any and or
all of this sig.
A little something for spam bots:

root at localhost postmaster at localhost admin at localhost
abuse at localhost postmaster at 127.0.0.1

Chairman William Kennard: bkennard at fcc.gov 
Commissioner Susan Ness: sness at fcc.gov
Commissioner Harold Furchtgott-Roth: hfurchtg at fcc.gov
Commissioner Michael Powell: mpowell at fcc.gov
Commissioner Gloria Tristani: gtristan at fcc.gov
consumerline at ftc.gov
fccinfo at fcc.gov
ssegal at fcc.gov





More information about the Python-list mailing list