aboutsummaryrefslogtreecommitdiffstats
path: root/report.c
Commit message (Collapse)AuthorAgeFilesLines
* Let logfile take precedence over syslog if and only if logfile is effective.Matthias Andree2009-05-291-5/+4
| | | | svn path=/branches/BRANCH_6-3/; revision=5349
* Fix format string bugs.Matthias Andree2009-05-041-1/+1
| | | | svn path=/branches/BRANCH_6-3/; revision=5291
* Add report_flush(fp) function (report.c).Matthias Andree2009-05-041-3/+16
| | | | svn path=/branches/BRANCH_6-3/; revision=5289
* Replace FF characters by LF.Matthias Andree2009-05-041-5/+4
| | | | svn path=/branches/BRANCH_6-3/; revision=5288
* Drop dead report_message_count.Matthias Andree2009-05-041-7/+0
| | | | svn path=/branches/BRANCH_6-3/; revision=5287
* Relocate and case-match errnum comment.Matthias Andree2009-05-041-4/+3
| | | | svn path=/branches/BRANCH_6-3/; revision=5286
* Add missing LF after partial message.Matthias Andree2009-05-041-1/+1
| | | | svn path=/branches/BRANCH_6-3/; revision=5285
* Rename use_stderr -> unbuffered (more descriptive).Matthias Andree2009-05-041-6/+6
| | | | svn path=/branches/BRANCH_6-3/; revision=5284
* pre { line-height: 125%; } td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# PopDel.py  Copyright Richard Harris 2002
#
# author: Richard Harris (rover@emptydog.com)
# The author releases this file under the GPL
# license. See COPYING for specifics.
#
# See PopDel.manual for the use of this Python class.
#
# created: 01 May 2002
# last modified: 27 Apr 2006
#
# change log:
# Matthias Andree, April 2006:
#	Bump version to 0.1+jc2 and mark Joshua Crawford
#	as additional author.
#	Reformat ESR's change log entry
#	Note: emptydog.com is currently not registered.
# Joshua Crawford, April 2006:
#	Display From: address.
#	List every email, even if it has no Subject: header.
#	  this also avoids indexing errors (that caused
#	  deleting the wrong message)
# Joshua Crawford, November 2004:
# 	Out of range error fixed.
#	Allow for all caps "SUBJECT:".
#	Display user and server name in messages.
#	Don't prompt for save if no changes.
#	Don't clear the screen until we're displaying a menu.
#	Check for invalid choice.
#	Check all arguments exist.
#	Check for errors in POP.
#	Return 1 on errors, 0 otherwise.
# Eric S. Raymond, January 2003:
#	Hacked to support message ranges.
#
import os, poplib, re, string, sys

class PopDel:
	HDR = "\nPopDel - Delete messages from popmail - Ver. 0.1+jc2"
	BYE = "\n  PopDel Ver.0.1+jc2 by Richard Harris and Joshua Crawford\n" +\
#		  "     site - http://emptydog.com/\n" +\
		  "     email - Richard Harris <rover@emptydog.com>\n" +\
		  "     email - Joshua Crawford <jgcrawford@gmail.com>\n"
	PROMPT1 = "Choose message number to delete or 'q' to quit: "
	PROMPT2 = "Quit or abort: "
	CHOICES = ["Save changes and quit.",
			   "Abort and make no deletions."]
	
	def __init__(self):
		self.done = 0
		self.dirty = 0
		return

	# get user to choose an element from thing
	def query(self, thing, prompt):
		length = len(thing)
		choice = [length+1]
		for i in range(0, length):
			print '(' + `i +  1` + ') ' + thing[i]
		while filter(lambda x: x > length, choice):
			choice = raw_input(prompt)
			if (choice == 'q'):
				self.done = 1
				choice = [-1]
			else:
				try:
					choice = map(int, string.split(choice, "-"))
				except:
					choice = [length + 1]
				if len(choice) > 1:
					choice = range(choice[0], choice[1]+1)
		return choice

	def run(self):
		#log in
		print self.HDR

		subjects = []

		if (len(sys.argv) < 4):
			print 'Usage: ' + sys.argv[0] + ' pop3.host.name username password'
			return 1

		try:
			M = poplib.POP3(sys.argv[1])
		except:
			print 'Could not reach ' + sys.argv[1]
			return 1
		try:
			M.user(sys.argv[2])
		except:
			print 'Bad username ' + sys.argv[2] + '@' + sys.argv[1]
			M.quit()
			return 1
		try:
			M.pass_(sys.argv[3])
		except:
			print 'Bad password for ' + sys.argv[2] + '@' + sys.argv[1]
			M.quit()
			return 1
#		M.set_debuglevel(1)
		try:
			messages = M.list()
		except:
			print 'Error reading listing for ' + sys.argv[2] + '@' + sys.argv[1]
			M.quit()
			return 1

		list = messages[1]
		if (len(list) == 0):
			M.quit()
			print '\nNo messages for ' + sys.argv[2] + '@' + sys.argv[1]
		else:
			for entry in list:
				tokens = string.split(entry)
				subject = '(no subject)'
				address = '(no address)'
				try:
					head = M.top(int(tokens[0]), 32)
				except:
					print 'Error issuing TOP command for ' + sys.argv[2] + '@' + sys.argv[1]
					if self.dirty:
						M.rset()
					M.quit()
					return 1
				for line in head[1]:
					if (string.find(string.upper(line), 'SUBJECT:') == 0):
						subject = line[9:]
					if (string.find(string.upper(line), 'FROM:') == 0):
						line = line[6:]
						result = re.search(r'([^\t <>]*@[^\t <>]*)', line)
						if (result != None):
							address = result.expand(r'\1')
				subj = address[:40] + ' [' + tokens[1] + 'o] ' + subject
				subjects.append(subj)

			while not self.done:
				os.system('clear')
				print self.HDR
				print '\nMessages for ' + sys.argv[2] + '@' + sys.argv[1] + ':'
				msglist = self.query(subjects, self.PROMPT1)
				print "Choice:", msglist
				for msg in msglist:
					if (msg > 0):
						try:
							M.dele(msg)
						except:
							print 'Error deleting message #' + `msg`
							if self.dirty:
								M.rset()
							M.quit()
							return 1
						self.dirty = 1
						subjects[msg-1] = subjects[msg-1] + ' -X-'

			if not self.dirty:
				M.quit()
			else:
				print '\nExit Options:'
				choice = self.query(self.CHOICES, self.PROMPT2)
				print "Choice:", choice
				if (choice == [1]):		# commit changes and quit
					M.quit()
				else:				# reset and quit
					M.rset()
					M.quit()

		print self.BYE
		return

#-----------------main
obj = PopDel()
sys.exit(obj.run())