*** D:\Documents and Settings\tameyer.MASSEY\Local Settings\Temp\TCV124d.tmp\OptionsClass.1.24.4.1.py	Thu Jun 10 16:52:17 2004
--- C:\spambayes_release_1_0-branch\spambayes\OptionsClass.py	Mon May 23 11:56:57 2005
***************
*** 234,239 ****
--- 234,259 ----
          strval += "\"%s\"\n\n" % (str(self.doc()))
          return strval
  
+     def as_documentation_string(self, section=None):
+         '''Summarise the option in a format suitable for unmodified
+         insertion in HTML documentation.'''
+         strval = ["<tr>"]
+         if section is not None:
+             strval.append("\t<td>[%s]</td>" % (section,))
+         strval.append("\t<td>%s</td>" % (self.name,))
+         strval.append("\t<td>%s</td>" % \
+                       ", ".join([str(s) for s in self.valid_input()]))
+         default = self.default()
+         if isinstance(default, types.TupleType):
+             default = ", ".join([str(s) for s in default])
+         else:
+             default = str(default)
+         strval.append("\t<td>%s</td>" % (default,))
+         strval.append("\t<td><strong>%s</strong>: %s</td>" \
+                       % (self.display_name(), self.doc()))
+         strval.append("</tr>\n")
+         return "\n".join(strval)
+ 
      def write_config(self, file):
          '''Output value in configuration file format.'''
          file.write(self.name)
***************
*** 610,615 ****
--- 630,656 ----
          '''Set an option.'''
          if self.conversion_table.has_key((sect, opt.lower())):
              sect, opt = self.conversion_table[sect, opt.lower()]
+             
+         # Annoyingly, we have a special case.  The notate_to and
+         # notate_subject allowed values have to be set to the same
+         # values as the header_x_ options, but this can't be done
+         # (AFAIK) dynmaically. If this isn't the case, then if the
+         # header_x_string values are changed, the notate_ options don't
+         # work.  Outlook Express users like both of these options...so
+         # we fix it here. See also sf #944109.
+         # This code was originally in Options.py, after loading in the
+         # options.  But that doesn't work, because if we are setting
+         # both in a config file, we need it done immediately.
+         # We now need the hack here, *and* in UserInterface.py
+         # For the moment, this will do.  Use a real mail client, for
+         # goodness sake!
+         if sect == "Headers" and opt in ("notate_to", "notate_subject"):
+             header_strings = (self.get("Headers", "header_ham_string"),
+                               self.get("Headers",
+                                        "header_spam_string"),
+                               self.get("Headers",
+                                        "header_unsure_string"))
+             return val in header_strings
          if self.is_valid(sect, opt, val):
              self._options[sect, opt.lower()].set(val)
          else:
***************
*** 696,703 ****
          all.sort()
          return all
  
!     def display(self):
          '''Display options in a config file form.'''
          output = StringIO.StringIO()
          keys = self._options.keys()
          keys.sort()
--- 737,745 ----
          all.sort()
          return all
  
!     def display(self, add_comments=False):
          '''Display options in a config file form.'''
+         import textwrap
          output = StringIO.StringIO()
          keys = self._options.keys()
          keys.sort()
***************
*** 710,720 ****
                  output.write(sect)
                  output.write("]\n")
                  currentSection = sect
              self._options[sect, opt].write_config(output)
          return output.getvalue()
  
!     def display_full(self, section=None, option=None):
!         '''Display options including all information.'''
          # Given that the Options class is no longer as nice looking
          # as it once was, this returns all the information, i.e.
          # the doc, default values, and so on
--- 752,768 ----
                  output.write(sect)
                  output.write("]\n")
                  currentSection = sect
+             if add_comments:
+                 doc = self._options[sect, opt].doc()
+                 if not doc:
+                     doc = "No information available, sorry."
+                 doc = re.sub(r"\s+", " ", doc)
+                 output.write("\n# %s\n" % ("\n# ".join(textwrap.wrap(doc)),))
              self._options[sect, opt].write_config(output)
          return output.getvalue()
  
!     def _display_nice(self, section, option, formatter):
!         '''Display a nice output of the options'''
          # Given that the Options class is no longer as nice looking
          # as it once was, this returns all the information, i.e.
          # the doc, default values, and so on
***************
*** 723,730 ****
          # when section and option are both specified, this
          # is nothing more than a call to as_nice_string
          if section is not None and option is not None:
!             output.write(self._options[section,
!                                        option.lower()].as_nice_string(section))
              return output.getvalue()
  
          all = self._options.keys()
--- 771,778 ----
          # when section and option are both specified, this
          # is nothing more than a call to as_nice_string
          if section is not None and option is not None:
!             opt = self._options[section, option.lower()]
!             output.write(getattr(opt, formatter)(section))
              return output.getvalue()
  
          all = self._options.keys()
***************
*** 732,739 ****
          for sect, opt in all:
              if section is not None and sect != section:
                  continue
!             output.write(self._options[sect, opt.lower()].as_nice_string(sect))
          return output.getvalue()
  
  # These are handy references to commonly used regex/tuples defining
  # permitted values. Although the majority of options use one of these,
--- 780,797 ----
          for sect, opt in all:
              if section is not None and sect != section:
                  continue
!             opt = self._options[sect, opt.lower()]
!             output.write(getattr(opt, formatter)(sect))
          return output.getvalue()
+ 
+     def display_full(self, section=None, option=None):
+         '''Display options including all information.'''
+         return self._display_nice(section, option, 'as_nice_string')
+         
+     def output_for_docs(self, section=None, option=None):
+         '''Return output suitable for inserting into documentation for
+         the available options.'''
+         return self._display_nice(section, option, 'as_documentation_string')
  
  # These are handy references to commonly used regex/tuples defining
  # permitted values. Although the majority of options use one of these,
