File indexing completed on 2024-11-03 11:24:06

0001 # -*- coding: UTF-8 -*-
0002 
0003 """
0004 Remove previous fields (C{#|...}) from messages.
0005 
0006 Documented in C{doc/user/sieving.docbook}.
0007 
0008 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>
0009 @license: GPLv3
0010 """
0011 
0012 from pology import _, n_
0013 from pology.report import report
0014 
0015 
0016 def setup_sieve (p):
0017 
0018     p.set_desc(_("@info sieve discription",
0019     "Remove previous fields (#| ...) from messages."
0020     ))
0021 
0022     p.add_param("all", bool,
0023                 desc=_("@info sieve parameter discription",
0024     "Remove previous fields from all messages "
0025     "(by default previous fields are not removed from fuzzy messages)."
0026     ))
0027 
0028 
0029 class Sieve (object):
0030 
0031     def __init__ (self, params):
0032 
0033         self.p = params
0034 
0035         self.ncleared = 0
0036 
0037 
0038     def process (self, msg, cat):
0039 
0040         if self.p.all or "fuzzy" not in msg.flag: # also for obsolete
0041             modcount = msg.modcount
0042             msg.msgctxt_previous = None
0043             msg.msgid_previous = None
0044             msg.msgid_plural_previous = None
0045             if modcount < msg.modcount:
0046                 self.ncleared += 1
0047 
0048 
0049     def finalize (self):
0050 
0051         if self.ncleared > 0:
0052             msg = n_("@info:progress",
0053                      "Cleared previous fields from %(num)d message.",
0054                      "Cleared previous fields from %(num)d messages.",
0055                      num=self.ncleared)
0056             report("===== " + msg)
0057