From: Andy T. <an...@us...> - 2005-12-13 11:13:45
|
Update of /cvsroot/pythoncard/PythonCard/samples/fpop In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19204/fpop Modified Files: emailfilter.py fpop.py fpoputil.py message.py preview.py Log Message: Removed all of the plain except: clauses I could Index: preview.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/fpop/preview.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** preview.py 12 Aug 2004 19:18:52 -0000 1.22 --- preview.py 13 Dec 2005 11:13:23 -0000 1.23 *************** *** 2,8 **** """ __version__ = "$Revision$" __date__ = "$Date$" - """ from PythonCard import dialog, log, model --- 2,11 ---- """ + This is intended as a sample for the MultiColumnList some day, though it's heavy on straight wxPython right now + + Goal: imitate the Windows utility "nPOP" (hence the temporary code name), with the following differences : + """ __version__ = "$Revision$" __date__ = "$Date$" from PythonCard import dialog, log, model *************** *** 155,163 **** print self.attachments[n] ## get_payload isn't working for some reason ! try: ! payload = self.msg.get_payload(partNumber, decode=1) ! print len(payload) ! except: ! print "ugh, get_payload partNumber didn't work" # but walking manually does?! --- 158,163 ---- print self.attachments[n] ## get_payload isn't working for some reason ! payload = self.msg.get_payload(partNumber, decode=1) ! print len(payload) # but walking manually does?! *************** *** 200,208 **** text = fpoputil.getBody(msg) ! try: ! comp.fldBody.text = text ! except: ! print "something went wrong with getting the text" ! print text self.attachments = fpoputil.getAttachments(msg) --- 200,204 ---- text = fpoputil.getBody(msg) ! comp.fldBody.text = text self.attachments = fpoputil.getAttachments(msg) Index: message.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/fpop/message.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** message.py 12 Aug 2004 19:18:52 -0000 1.17 --- message.py 13 Dec 2005 11:13:23 -0000 1.18 *************** *** 62,69 **** text = fpoputil.getBody(msg) ! try: ! comp.fldBody.text = text ! except: ! print text def on_menuFileClose_select(self, event): --- 62,66 ---- text = fpoputil.getBody(msg) ! comp.fldBody.text = text def on_menuFileClose_select(self, event): *************** *** 76,86 **** def on_send_command(self, event): comp = self.components ! try: references = self.msg['references'] ! except: references = None ! try: inReplyTo = self.msg['in-reply-to'] ! except: inReplyTo = None --- 73,83 ---- def on_send_command(self, event): comp = self.components ! if self.msg.has_key('references'): references = self.msg['references'] ! else: references = None ! if self.msg.has_key('in-reply-to'): inReplyTo = self.msg['in-reply-to'] ! else: inReplyTo = None Index: fpop.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/fpop/fpop.py,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** fpop.py 30 Aug 2004 14:42:47 -0000 1.48 --- fpop.py 13 Dec 2005 11:13:23 -0000 1.49 *************** *** 287,291 **** # Nothing to resize return - listWidth = listX.GetSize().width if listX.GetItemCount() > listX.GetCountPerPage(): --- 287,290 ---- *************** *** 293,301 **** scrollWidth = wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X) listWidth = listWidth - scrollWidth - totColWidth = 0 # Sum width of columns index, date & size (after auto-sizing) for col in (0, 3,4): totColWidth = totColWidth + listX.GetColumnWidth(col) - # allow for platform-dependant number of extra pixels for correct sizing. Highly empirical. if wx.Platform == '__WXMSW__': --- 292,298 ---- *************** *** 305,309 **** else: margin = 0 - # Resize the subject & sender columns to take up the remaining available space (60/40 ratio) leftover = listWidth - totColWidth - margin --- 302,305 ---- *************** *** 311,321 **** listX.SetColumnWidth(2, int(leftover * .4)) - def on_btnExit_mouseClick(self, event): self.close() - # this doesn't really process the blacklist - # just dumps the msgs so we can debug what we have def doProcessBlacklist(self): for key, value in self.msgs.iteritems(): print "key", key --- 307,316 ---- listX.SetColumnWidth(2, int(leftover * .4)) def on_btnExit_mouseClick(self, event): self.close() def doProcessBlacklist(self): + # this doesn't really process the blacklist + # just dumps the msgs so we can debug what we have for key, value in self.msgs.iteritems(): print "key", key *************** *** 379,383 **** try: headers = headers[:headers.index('')] ! except: print "can't find blank line in", i headers = '\n'.join(headers) --- 374,378 ---- try: headers = headers[:headers.index('')] ! except ValueError: print "can't find blank line in", i headers = '\n'.join(headers) *************** *** 710,714 **** msg = email.message_from_string(text) self.previewWindow.displayMessage(msg, index - 1, self.msgs[index - 1][HEADERS_INDEX]) ! except: print "\n\n *** conversion failed, here's the message ***\n" + \ " *** it will also be written to badmessage.txt ***" --- 705,709 ---- msg = email.message_from_string(text) self.previewWindow.displayMessage(msg, index - 1, self.msgs[index - 1][HEADERS_INDEX]) ! except TypeError: print "\n\n *** conversion failed, here's the message ***\n" + \ " *** it will also be written to badmessage.txt ***" *************** *** 718,722 **** f.write(text) f.close() - self.statusBar.text = '' --- 713,716 ---- Index: emailfilter.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/fpop/emailfilter.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** emailfilter.py 8 Aug 2004 18:31:53 -0000 1.6 --- emailfilter.py 13 Dec 2005 11:13:23 -0000 1.7 *************** *** 51,88 **** def getAttachments(msg): attachments = [] ! try: ! # try MIME ! counter = 0 ! for part in msg.walk(): ! # multipart/* are just containers ! partType = part.get_type() ! if part.get_main_type() == 'multipart': ! continue ! filename = part.get_filename() ! ### this part is new ! ### contributed by Andrew Dalke ! ### for MS Update virus ! if filename is None: ! if partType in ["application/x-msdownload", ! "audio/x-wav", "audio/x-midi"]: ! # Kill with extreme prejudice ! filename = "virus.exe" ! ! #### end of new part ! if filename is not None: ! if not filename: ! ext = mimetypes.guess_extension(part.get_type()) ! if not ext: ! # Use a generic bag-of-bits extension ! ext = '.bin' ! filename = 'part-%03d%s' % (counter, ext) ! #print counter, partType, filename ! attachments.append({'part':counter, 'type':partType, 'filename':filename}) ! counter += 1 ! except: ! pass return attachments - # delete "failure notice" messages too? # these are returned messages where the virus --- 51,84 ---- def getAttachments(msg): attachments = [] ! # try MIME ! counter = 0 ! for part in msg.walk(): ! # multipart/* are just containers ! partType = part.get_type() ! if part.get_main_type() == 'multipart': ! continue ! filename = part.get_filename() ! ### this part is new ! ### contributed by Andrew Dalke ! ### for MS Update virus ! if filename is None: ! if partType in ["application/x-msdownload", ! "audio/x-wav", "audio/x-midi"]: ! # Kill with extreme prejudice ! filename = "virus.exe" ! ! #### end of new part ! if filename is not None: ! if not filename: ! ext = mimetypes.guess_extension(part.get_type()) ! if not ext: ! # Use a generic bag-of-bits extension ! ext = '.bin' ! filename = 'part-%03d%s' % (counter, ext) ! #print counter, partType, filename ! attachments.append({'part':counter, 'type':partType, 'filename':filename}) ! counter += 1 return attachments # delete "failure notice" messages too? # these are returned messages where the virus *************** *** 183,203 **** if __name__ == '__main__': ! try: ! if len(sys.argv) == 4: ! server = sys.argv[1] ! username = sys.argv[2] ! password = sys.argv[3] else: ! if len(sys.argv) == 2: ! path = sys.argv[1] ! else: ! path = DEFAULTINI ! parser = ConfigParser.ConfigParser() ! parser.read(path) ! server = parser.get('Account', 'server') ! username = parser.get('Account', 'username') ! password = parser.get('Account', 'password') ! processMailbox(server, username, password) ! except: ! print USAGE ! --- 179,195 ---- if __name__ == '__main__': ! if len(sys.argv) == 4: ! server = sys.argv[1] ! username = sys.argv[2] ! password = sys.argv[3] ! else: ! if len(sys.argv) == 2: ! path = sys.argv[1] else: ! path = DEFAULTINI ! parser = ConfigParser.ConfigParser() ! parser.read(path) ! server = parser.get('Account', 'server') ! username = parser.get('Account', 'username') ! password = parser.get('Account', 'password') ! processMailbox(server, username, password) Index: fpoputil.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/fpop/fpoputil.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** fpoputil.py 13 Jan 2003 17:50:33 -0000 1.12 --- fpoputil.py 13 Dec 2005 11:13:23 -0000 1.13 *************** *** 5,9 **** """ ! import rfc822 ORIGINAL_MESSAGE_HEADER = '-----Original Message-----' --- 5,9 ---- """ ! import rfc822, datetime ORIGINAL_MESSAGE_HEADER = '-----Original Message-----' *************** *** 18,45 **** return tztuple else: ! # numsec isn't used for anything?! ! try: ! #numsec = time.mktime(tztuple) ! return "%02d/%02d/%d %02d:%02d" % (tztuple[1],tztuple[2],tztuple[0],tztuple[3],tztuple[4]) ! except: ! #numsec = 0 ! return '' ! def joinList(listX): ! try: ! text = ", ".join(listX) ! return text.replace('\n', '') ! except: ! return "" def filteredSubject(subject): # chop out spam identifier by getting rid of spaces # and id after main subject ! try: ! listX = subject.split(' ') ! return listX[0] ! except: ! return subject # the blacklist is stored in a blacklist.txt --- 18,32 ---- return tztuple else: ! return datetime.datetime(tztuple[0], tztuple[1], tztuple[2], tztuple[3], tztuple[4]).strftime('%m/%d/%y %H:%M') def joinList(listX): ! text = ", ".join(listX) ! return text.replace('\n', '') def filteredSubject(subject): # chop out spam identifier by getting rid of spaces # and id after main subject ! listX = subject.split(' ') ! return listX[0] # the blacklist is stored in a blacklist.txt *************** *** 56,60 **** for i in listX: dictX[i] = None ! except: dictX = {} return dictX --- 43,47 ---- for i in listX: dictX[i] = None ! except IOError: dictX = {} return dictX *************** *** 68,72 **** f.write(temp) f.close() ! except: print "argh, couldn't write the file, what do we do?" --- 55,59 ---- f.write(temp) f.close() ! except IOError: print "argh, couldn't write the file, what do we do?" *************** *** 96,146 **** text = msg.get_payload(decode=1) else: - try: - # try MIME - counter = 0 - text = None - for part in msg.walk(): - # multipart/* are just containers - partType = part.get_type() - print counter, partType - if part.get_main_type() == 'multipart': - continue - if partType in ['text/plain', 'text/html']: - if text is None: - # only display the first payload - # but there might be attachments... - text = part.get_payload(decode=1) - counter += 1 - # I'm not sure when this case would occur - # so it might be pointless - if text is None and msg.get_main_type in ['text/plain', 'text/html']: - text = msg.get_payload(decode=1) - except: - text = msg.get_payload(decode=1) - return text - - def getAttachments(msg): - attachments = [] - try: # try MIME counter = 0 for part in msg.walk(): # multipart/* are just containers partType = part.get_type() if part.get_main_type() == 'multipart': continue ! filename = part.get_filename() ! if filename is not None: ! if not filename: ! ext = mimetypes.guess_extension(part.get_type()) ! if not ext: ! # Use a generic bag-of-bits extension ! ext = '.bin' ! filename = 'part-%03d%s' % (counter, ext) ! print counter, partType, filename ! attachments.append({'part':counter, 'type':partType, 'filename':filename}) counter += 1 ! except: ! pass return attachments --- 83,127 ---- text = msg.get_payload(decode=1) else: # try MIME counter = 0 + text = None for part in msg.walk(): # multipart/* are just containers partType = part.get_type() + print counter, partType if part.get_main_type() == 'multipart': continue ! if partType in ['text/plain', 'text/html']: ! if text is None: ! # only display the first payload ! # but there might be attachments... ! text = part.get_payload(decode=1) counter += 1 ! # I'm not sure when this case would occur ! # so it might be pointless ! if text is None and msg.get_main_type in ['text/plain', 'text/html']: ! text = msg.get_payload(decode=1) ! return text ! ! def getAttachments(msg): ! attachments = [] ! # try MIME ! counter = 0 ! for part in msg.walk(): ! # multipart/* are just containers ! partType = part.get_type() ! if part.get_main_type() == 'multipart': ! continue ! filename = part.get_filename() ! if filename is not None: ! if not filename: ! ext = mimetypes.guess_extension(part.get_type()) ! if not ext: ! # Use a generic bag-of-bits extension ! ext = '.bin' ! filename = 'part-%03d%s' % (counter, ext) ! print counter, partType, filename ! attachments.append({'part':counter, 'type':partType, 'filename':filename}) ! counter += 1 return attachments |