[Spambayes-checkins] spambayes/spambayes OptionConfig.py,1.7,1.8

Tony Meyer anadelonbrin at users.sourceforge.net
Wed Mar 12 19:25:00 EST 2003


Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv29590/spambayes

Modified Files:
	OptionConfig.py 
Log Message:
Update OptionConfig so that boolean options are presented as radio buttons rather than a text box, and multiple choice options are presented as checkboxes. Broke up the pop3proxy options into pop3proxy options and header options, as the pop3proxy section was too big to be nice - and this hopefully fits with the migration of header options into a separate module.

Index: OptionConfig.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/OptionConfig.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** OptionConfig.py	11 Mar 2003 02:48:29 -0000	1.7
--- OptionConfig.py	13 Mar 2003 03:24:57 -0000	1.8
***************
*** 10,14 ****
  
  To Do:
!     o Replace some of the test options with radio buttons/checkboxes.
      o Suggestions?
  
--- 10,20 ----
  
  To Do:
!     o Checkboxes need a default value (i.e. what to set the option as
!       when no boxes are checked).  This needs to be thought about and
!       then implemented.  add_id is an example of what it does at the
!       moment.
!     o The values check could be much more generic.  Acceptable values are
!       (mostly) already in the code, so they can be tested against, in a
!       loop, rather than lots of individual, specific, pieces of code.
      o Suggestions?
  
***************
*** 21,24 ****
--- 27,32 ----
  __author__ = "Tim Stone <tim at fourstonesExpressions.com>"
  # Blame for bugs caused by using Dibbler: Richie Hindle <richie at entrian.com>
+ # Blame for bugs caused by the radio buttons / checkboxes: Tony Meyer
+ # <ta-meyer at ihug.co.nz>
  
  try:
***************
*** 69,76 ****
  # This governs the order in which the options appear on the configurator
  # page, and the headings and help text that are used.
  page_layout = \
  (
      ("POP3 Options",
!     (   ("p3servers", "Servers",
           """The Spambayes POP3 proxy intercepts incoming email and classifies
           it before sending it on to your email client.  You need to specify
--- 77,85 ----
  # This governs the order in which the options appear on the configurator
  # page, and the headings and help text that are used.
+ # The field type may be "text", "rb" (radio button), or "cb" (checkbox)
  page_layout = \
  (
      ("POP3 Options",
!     (   ("p3servers", "Servers", "text", None,
           """The Spambayes POP3 proxy intercepts incoming email and classifies
           it before sending it on to your email client.  You need to specify
***************
*** 85,89 ****
           Spambayes."""),
  
!         ("p3ports", "Ports",
           """Each POP3 server that is being monitored must be assigned to a
           'port' in the Spambayes POP3 proxy.  This port must be different for
--- 94,98 ----
           Spambayes."""),
  
!         ("p3ports", "Ports", "text", None,
           """Each POP3 server that is being monitored must be assigned to a
           'port' in the Spambayes POP3 proxy.  This port must be different for
***************
*** 93,97 ****
           specify the same number of ports as servers, separated by commas."""),
           
!         ("p3notateto", "Notate To",
           """Some email clients (Outlook Express, for example) can only
           set up filtering rules on a limited set of headers.  These
--- 102,106 ----
           specify the same number of ports as servers, separated by commas."""),
           
!         ("p3notateto", "Notate To", "rb", ("True", "False"),
           """Some email clients (Outlook Express, for example) can only
           set up filtering rules on a limited set of headers.  These
***************
*** 106,114 ****
           mail classification."""),
  
!        ("p3notatesub", "Notate Subject",
           """This option will add the same information as Notate to:,
           but to the start of the mail subject line."""),
  
!        ("p3cachemsg", "Cache Messages",
           """You can disable the pop3proxy caching of messages.  This
           will make the proxy a bit faster, and make it use less space
--- 115,123 ----
           mail classification."""),
  
!        ("p3notatesub", "Notate Subject", "rb", ("True", "False"),
           """This option will add the same information as Notate to:,
           but to the start of the mail subject line."""),
  
!        ("p3cachemsg", "Cache Messages", "rb", ("True", "False"),
           """You can disable the pop3proxy caching of messages.  This
           will make the proxy a bit faster, and make it use less space
***************
*** 118,123 ****
           Thus, you should only turn caching off when you are satisfied
           with the filtering that Spambayes is doing for you."""),
  
!         ("p3addid", "Add id tag",
           """If you wish to be able to find a specific message (via the 'find'
           box on the <a href="home">home</a> page), or use the SMTP proxy to
--- 127,135 ----
           Thus, you should only turn caching off when you are satisfied
           with the filtering that Spambayes is doing for you."""),
+     )),
  
!     ("Header Options",
!     (   ("p3addid", "Add id tag", "cb",
!          ("header", "body"),
           """If you wish to be able to find a specific message (via the 'find'
           box on the <a href="home">home</a> page), or use the SMTP proxy to
***************
*** 128,136 ****
           do not offer these capabilities.  For these clients, you will need to
           have the id added to the body of the message.  If you are not sure,
!          the safest option is to use both.  Valid options include neither
!          the header nor the body (leave this blank), header only ("header"),
!          body only ("body"), or both ("header body")."""),
  
!         ("p3stripid", "Strip incoming ids",
           """If you receive messages from other spambayes users, you might
           find that incoming mail (generally replies) already has an id,
--- 140,146 ----
           do not offer these capabilities.  For these clients, you will need to
           have the id added to the body of the message.  If you are not sure,
!          the safest option is to use both."""),
  
!         ("p3stripid", "Strip incoming ids", "rb", ("True", "False"),
           """If you receive messages from other spambayes users, you might
           find that incoming mail (generally replies) already has an id,
***************
*** 141,145 ****
           ids from incoming mail."""),
  
!         ("p3prob", "Add spam probability header",
           """You can have spambayes insert a header with the calculated spam
           probability into each mail.  If you can view headers with your
--- 151,155 ----
           ids from incoming mail."""),
  
!         ("p3prob", "Add spam probability header", "rb", ("True", "False"),
           """You can have spambayes insert a header with the calculated spam
           probability into each mail.  If you can view headers with your
***************
*** 147,151 ****
           and even instructive if you're a serious spambayes junkie."""),
          
!         ("p3thermostat", "Add spam level header",
           """You can have spambayes insert a header with the calculated spam
           probability, expressed as a number of '*'s, into each mail (the more
--- 157,161 ----
           and even instructive if you're a serious spambayes junkie."""),
          
!         ("p3thermostat", "Add spam level header", "rb", ("True", "False"),
           """You can have spambayes insert a header with the calculated spam
           probability, expressed as a number of '*'s, into each mail (the more
***************
*** 154,158 ****
           classification of ham/spam, ignoring the classification given."""),
          
!         ("p3evidence", "Add evidence header",
           """You can have spambayes insert a header into mail, with the
           evidence that it used to classify that message (a collection of
--- 164,168 ----
           classification of ham/spam, ignoring the classification given."""),
          
!         ("p3evidence", "Add evidence header", "rb", ("True", "False"),
           """You can have spambayes insert a header into mail, with the
           evidence that it used to classify that message (a collection of
***************
*** 160,168 ****
           with your mailer, then this may give you some insight as to why
           a particular message was scored in a particular way."""),
- 
      )),
  
      ("SMTP Options",
!     (   ("smtpservers", "Servers",
           """The Spambayes SMTP proxy intercepts outgoing email - if you have
           sent it to one of the addresses below, it is examined for an id and
--- 170,177 ----
           with your mailer, then this may give you some insight as to why
           a particular message was scored in a particular way."""),
      )),
  
      ("SMTP Options",
!     (   ("smtpservers", "Servers", "text", None,
           """The Spambayes SMTP proxy intercepts outgoing email - if you have
           sent it to one of the addresses below, it is examined for an id and
***************
*** 179,183 ****
           Spambayes."""),
  
!         ("smtpports", "Ports",
           """Each SMTP server that is being monitored must be assigned to a
           'port' in the Spambayes SMTP proxy.  This port must be different for
--- 188,192 ----
           Spambayes."""),
  
!         ("smtpports", "Ports", "text", None,
           """Each SMTP server that is being monitored must be assigned to a
           'port' in the Spambayes SMTP proxy.  This port must be different for
***************
*** 187,191 ****
           specify the same number of ports as servers, separated by commas."""),
           
!         ("smtpham", "Ham Address",
           """When a message is received that you wish to train on (for example,
           one that was incorrectly classified), you need to forward or bounce
--- 196,200 ----
           specify the same number of ports as servers, separated by commas."""),
           
!         ("smtpham", "Ham Address", "text", None,
           """When a message is received that you wish to train on (for example,
           one that was incorrectly classified), you need to forward or bounce
***************
*** 195,199 ****
           a valid email address, like ham at nowhere.nothing."""),
  
!         ("smtpspam", "Spam Address",
           """As with Ham Address above, but the address that you need to forward
           or bounce mail that you wish to train as spam.  You will want to use
--- 204,208 ----
           a valid email address, like ham at nowhere.nothing."""),
  
!         ("smtpspam", "Spam Address", "text", None,
           """As with Ham Address above, but the address that you need to forward
           or bounce mail that you wish to train as spam.  You will want to use
***************
*** 203,207 ****
  
      ("Statistics Options",
!     (   ("hamcutoff", "Ham Cutoff",
           """Spambayes gives each email message a spam probability between
           0 and 1. Emails below the Ham Cutoff probability are classified
--- 212,216 ----
  
      ("Statistics Options",
!     (   ("hamcutoff", "Ham Cutoff", "text", None, 
           """Spambayes gives each email message a spam probability between
           0 and 1. Emails below the Ham Cutoff probability are classified
***************
*** 211,215 ****
           and should be smaller than the Spam Cutoff."""),
  
!         ("spamcutoff", "Spam Cutoff",
           """Emails with a spam probability above the Spam Cutoff are
           classified as Spam - just like the Ham Cutoff but at the other
--- 220,224 ----
           and should be smaller than the Spam Cutoff."""),
  
!         ("spamcutoff", "Spam Cutoff", "text", None,
           """Emails with a spam probability above the Spam Cutoff are
           classified as Spam - just like the Ham Cutoff but at the other
***************
*** 217,221 ****
           are classified as Unsure."""),
  
!         ("dbname", "Database filename",
           """Spambayes builds a database of information that it gathers
           from incoming emails and from you, the user, to get better and
--- 226,230 ----
           are classified as Unsure."""),
  
!         ("dbname", "Database filename", "text", None,
           """Spambayes builds a database of information that it gathers
           from incoming emails and from you, the user, to get better and
***************
*** 308,315 ****
              # then blank out the example rows to make way for the real ones.
              configTable = self.html.configTable.clone()
!             configRow1 = configTable.configRow1.clone()
              configRow2 = configTable.configRow2.clone()
              blankRow = configTable.blankRow.clone()
!             del configTable.configRow1
              del configTable.configRow2
              del configTable.blankRow
--- 317,328 ----
              # then blank out the example rows to make way for the real ones.
              configTable = self.html.configTable.clone()
!             configTextRow1 = configTable.configTextRow1.clone()
!             configRbRow1 = configTable.configRbRow1.clone()
!             configCbRow1 = configTable.configCbRow1.clone()
              configRow2 = configTable.configRow2.clone()
              blankRow = configTable.blankRow.clone()
!             del configTable.configTextRow1
!             del configTable.configRbRow1
!             del configTable.configCbRow1
              del configTable.configRow2
              del configTable.blankRow
***************
*** 319,333 ****
              # value.
              isFirstRow = True
!             for name, label, unusedHelp in values:
!                 newConfigRow1 = configRow1.clone()
!                 newConfigRow2 = configRow2.clone()
                  currentValue = bcini.get(parm_ini_map[name][PIMapSect], \
                                           parm_ini_map[name][PIMapOpt])
  
                  # If this is the first row, insert the help text in a cell
                  # with a `rowspan` that covers all the rows.
                  if isFirstRow:
                      entries = []
!                     for unusedName, topic, help in values:
                          entries.append("<p><b>%s: </b>%s</p>" % (topic, help))
                      newConfigRow1.helpSpacer = '&nbsp;' * 10
--- 332,379 ----
              # value.
              isFirstRow = True
!             for name, label, fldtype, validInput, unusedHelp in values:
                  currentValue = bcini.get(parm_ini_map[name][PIMapSect], \
                                           parm_ini_map[name][PIMapOpt])
  
+                 # Populate the rows with the details and add them to the table.
+                 if fldtype == "text":
+                    newConfigRow1 = configTextRow1.clone()
+                    newConfigRow1.label = label
+                    newConfigRow1.input.name = name
+                    newConfigRow1.input.value = currentValue
+                 elif fldtype == "rb":
+                    newConfigRow1 = configRbRow1.clone()
+                    newConfigRow1.label = label
+                    newConfigRow1.inputT.name = name
+                    newConfigRow1.inputF.name = name
+                    if currentValue == "True":
+                       newConfigRow1.inputT.checked = "checked"
+                    elif currentValue == "False":
+                       newConfigRow1.inputF.checked = "checked"
+                 elif fldtype == "cb":
+                    newConfigRow1 = configCbRow1.clone()
+                    newConfigRow1.label = label
+                    blankOption = newConfigRow1.input.clone()
+                    firstOpt = True
+                    i = 0
+                    for val in validInput:
+                       newOption = blankOption.clone()
+                       newOption.val_label = val
+                       newOption.input_box.name = name + '-' + str(i)
+                       i += 1
+                       newOption.input_box.value = val
+                       if val in currentValue.split():
+                          newOption.input_box.checked = "checked"
+                       if firstOpt:
+                          newConfigRow1.input = newOption
+                          firstOpt = False
+                       else:
+                          newConfigRow1.input += newOption
+                     
                  # If this is the first row, insert the help text in a cell
                  # with a `rowspan` that covers all the rows.
                  if isFirstRow:
                      entries = []
!                     for name, topic, type, vals, help in values:
                          entries.append("<p><b>%s: </b>%s</p>" % (topic, help))
                      newConfigRow1.helpSpacer = '&nbsp;' * 10
***************
*** 337,344 ****
                      del newConfigRow1.helpCell
  
!                 # Populate the rows with the details and add them to the table.
!                 newConfigRow1.label = label
!                 newConfigRow1.input.name = name
!                 newConfigRow1.input.value = currentValue
                  newConfigRow2.currentValue = currentValue
                  configTable += newConfigRow1 + newConfigRow2 + blankRow
--- 383,387 ----
                      del newConfigRow1.helpCell
  
!                 newConfigRow2 = configRow2.clone()
                  newConfigRow2.currentValue = currentValue
                  configTable += newConfigRow1 + newConfigRow2 + blankRow
***************
*** 392,395 ****
--- 435,450 ----
  
  def editInput(parms):
+     # This is really a bit of a kludge, and a nicer solution would
+     # be most welcome.  Most especially, note that this will fall
+     # apart if there are more than 9 checkboxes in an option, or
+     # if "-" appears as the second-to-last character in an option
+     # value
+     for name, value in parms.items():
+        if name[-2:-1] == '-':
+           if parms.has_key(name[:-2]):
+              parms[name[:-2]] += ' ' + value
+           else:
+              parms[name[:-2]] = value
+           del parms[name]
  
      errmsg = ''
***************
*** 494,498 ****
          aid = parms['p3addid']
      except KeyError:
!         aid = options.pop3proxy_add_mailid_to
              
      if not aid == "" and not aid == "body" \
--- 549,554 ----
          aid = parms['p3addid']
      except KeyError:
!         parms['p3addid'] = "" # checkboxes need a default!
!         aid = parms['p3addid']
              
      if not aid == "" and not aid == "body" \





More information about the Spambayes-checkins mailing list