Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17124/spambayes
Modified Files:
OptionsClass.py
Log Message:
Fix the handling of the notate_to and notate_subject options. Previously,
although
these could be set to whatever the header_X_string options were, that could
only
be at runtime, not when loading in the config string - so they would revert
whenever
spambayes was restarted.
Now we special case them all over the damn place (stupid OE). Here we do the
special
case for setting the options.
Index: OptionsClass.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/OptionsClass.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** OptionsClass.py 16 Mar 2005 03:37:11 -0000 1.27
--- OptionsClass.py 22 May 2005 03:32:56 -0000 1.28
***************
*** 98,101 ****
--- 98,116 ----
return not not val
+ try:
+ import textwrap
+ raise ImportError
+ except ImportError:
+ # textwrap was added in 2.3
+ # We only use this for printing out errors and docstrings, so
+ # it doesn't need to be great (if you want it great, get a more
+ # recent Python!). So we do it the dumb way; the textwrap code
+ # could be duplicated here if anyone cared.
+ def wrap(s):
+ length = 10
+ return [s[i:i+length].strip() for i in xrange(0, len(s), length)]
+ else:
+ wrap = textwrap.wrap
+
__all__ = ['OptionsClass',
'HEADER_NAME', 'HEADER_VALUE',
***************
*** 654,662 ****
if self.conversion_table.has_key((sect, opt.lower())):
sect, opt = self.conversion_table[sect, opt.lower()]
if self.is_valid(sect, opt, val):
self._options[sect, opt.lower()].set(val)
else:
! print >> sys.stderr, ("Attempted to set [%s] %s with invalid"
! " value %s (%s)" %
(sect, opt.lower(), val, type(val)))
--- 669,698 ----
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:
! print >> sys.stderr, ("Attempted to set [%s] %s with "
! "invalid value %s (%s)" %
(sect, opt.lower(), val, type(val)))
***************
*** 685,689 ****
def _report_option_error(self, sect, opt, val, stream, msg):
- import textwrap
if sect in self.sections():
vopts = self.options(True)
--- 721,724 ----
***************
*** 694,698 ****
print >> stream, "Valid options for", sect, "are:"
vopts = ', '.join(vopts)
! vopts = textwrap.wrap(vopts)
for line in vopts:
print >> stream, ' ', line
--- 729,733 ----
print >> stream, "Valid options for", sect, "are:"
vopts = ', '.join(vopts)
! vopts = wrap(vopts)
for line in vopts:
print >> stream, ' ', line
***************
*** 703,707 ****
print >> stream, "Valid sections are:"
vsects = ', '.join(self.sections())
! vsects = textwrap.wrap(vsects)
for line in vsects:
print >> stream, ' ', line
--- 738,742 ----
print >> stream, "Valid sections are:"
vsects = ', '.join(self.sections())
! vsects = wrap(vsects)
for line in vsects:
print >> stream, ' ', line
***************
*** 742,746 ****
def display(self, add_comments=False):
'''Display options in a config file form.'''
- import textwrap
output = StringIO.StringIO()
keys = self._options.keys()
--- 777,780 ----
***************
*** 760,764 ****
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()
--- 794,798 ----
doc = "No information available, sorry."
doc = re.sub(r"\s+", " ", doc)
! output.write("\n# %s\n" % ("\n# ".join(wrap(doc)),))
self._options[sect, opt].write_config(output)
return output.getvalue()
_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins