]> git.pld-linux.org Git - packages/archivemail.git/blob - archivemail-add-archive-all-switch.patch
BR: rpmbuild(macros) >= 1.710
[packages/archivemail.git] / archivemail-add-archive-all-switch.patch
1 # Description: add, document and test --all option
2 # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=470675
3 # Author: Serafeim Zanikolas <serzan@hellug.gr>
4 # Last-Update: 2009-02-22
5 Index: archivemail/archivemail
6 ===================================================================
7 --- archivemail.orig/archivemail        2008-09-06 15:11:32.000000000 +0100
8 +++ archivemail/archivemail     2008-09-06 15:14:23.000000000 +0100
9 @@ -179,6 +179,7 @@
10      delete_old_mail      = 0
11      dry_run              = 0
12      filter_append        = None
13 +    archive_all          = 0
14      include_flagged      = 0
15      lockfile_attempts    = 5  
16      lockfile_extension   = ".lock"
17 @@ -209,14 +210,14 @@
18  
19          """
20          try:
21 -            opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uvp:', 
22 +            opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uvp:',
23                               ["date=", "days=", "delete", "dry-run", "help",
24                               "include-flagged", "no-compress", "output-dir=",
25                               "archive-name=",
26                               "filter-append=", "pwfile=", "dont-mangle",
27                               "preserve-unread", "quiet", "size=", "suffix=",
28                               "verbose", "version", "warn-duplicate", "copy",
29 -                             "prefix="])
30 +                             "prefix=", "all"])
31          except getopt.error, msg:
32              user_error(msg)
33  
34 @@ -227,6 +228,8 @@
35                  if self.copy_old_mail: 
36                      user_error("found conflicting options --copy and --delete")
37                  self.delete_old_mail = 1
38 +            if o == ('--all'):
39 +                self.archive_all = 1
40              if o == '--include-flagged':
41                  self.include_flagged = 1
42              if o == '--no-compress':
43 @@ -277,6 +280,9 @@
44              if o in ('-V', '--version'):
45                  print __version__ + "\n\n" + __copyright__
46                  sys.exit(0)
47 +        if self.archive_all and archive_by:
48 +            user_error("--all must not be used with other " +
49 +                       "filtering options")
50          return args
51  
52      def sanity_check(self):
53 @@ -681,6 +687,8 @@
54  mailbox compressed with gzip. 
55  
56  Options are as follows:
57 +      --all             archive all messages (not to be used along with other
58 +                        filter switches; use with caution)
59    -d, --days=NUM        archive messages older than NUM days (default: %d)
60    -D, --date=DATE       archive messages older than DATE
61    -o, --output-dir=DIR  directory to store archives (default: same as original)
62 @@ -1009,6 +1017,8 @@
63  
64  def should_archive(message):
65      """Return true if we should archive the message, false otherwise"""
66 +    if options.archive_all:
67 +        return 1
68      old = 0
69      time_message = guess_delivery_time(message)
70      if options.date_old_max == None:
71 Index: archivemail/archivemail.sgml
72 ===================================================================
73 --- archivemail.orig/archivemail.sgml   2008-09-06 15:11:32.000000000 +0100
74 +++ archivemail/archivemail.sgml        2008-09-06 15:16:25.000000000 +0100
75 @@ -119,6 +119,15 @@
76  
77  <VarListEntry>
78  <Term>
79 +    <Option>--all</Option>
80 +</Term>
81 +<ListItem><Para>
82 +Archive _all_ messages. Not to be combined with other filter switches.
83 +</Para></ListItem>
84 +</VarListEntry>
85 +
86 +<VarListEntry>
87 +<Term>
88      <Option>-d <Replaceable/NUM/, --days=<Replaceable/NUM/</Option>
89  </Term>
90  <ListItem><Para>Archive messages older than <Replaceable/NUM/ days.  
91 Index: archivemail/test_archivemail.py
92 ===================================================================
93 --- archivemail.orig/test_archivemail.py        2008-09-06 15:13:17.000000000 +0100
94 +++ archivemail/test_archivemail.py     2008-09-06 19:58:49.000000000 +0100
95 @@ -974,6 +974,44 @@
96          super(TestArchiveDryRun, self).tearDown()
97  
98  
99 +class TestArchiveAll(TestCaseInTempdir):
100 +    """make sure the 'all' option works"""
101 +    def setUp(self):
102 +        super(TestArchiveAll, self).setUp()
103 +        archivemail.options.quiet = 1
104 +
105 +    def testValidUse(self):
106 +        """test that it works when used without any other archive_by option"""
107 +        for execute in ("package", "system_long"):
108 +            self.setUp()
109 +            self.mbox_name = make_mbox(messages=3, hours_old=(24 * 12))
110 +            self.mbox = archivemail.Mbox(self.mbox_name)
111 +            if execute == "package":
112 +                archivemail.options.archive_all = 1
113 +                archivemail.archive(self.mbox_name)
114 +            elif execute == "system_long":
115 +                run = "./archivemail.py --all --quiet "\
116 +                        + "%s 2>&1 >/dev/null" % self.mbox_name
117 +                self.assertEqual(os.system(run), 0)
118 +            else:
119 +                sys.exit(1)
120 +            assert(os.path.exists(self.mbox_name))
121 +            self.assertTrue(self.mbox.is_empty())
122 +            self.tearDown()
123 +
124 +    def testInvalidUses(self):
125 +        """test that it gives up with invoked with either -d or -D"""
126 +        for arg in ["-d 30", "--days=30",\
127 +                    "-D 2008-07-30", "--date=2008-07-30"]:
128 +            run = ("./archivemail.py --all %s --quiet "\
129 +                    + "whatever >/dev/null 2>&1") % arg
130 +            self.assertEqual(os.system(run), 256)
131 +
132 +    def tearDown(self):
133 +        archivemail.options.archive_all = 0
134 +        archivemail.options.quiet = 0
135 +        super(TestArchiveAll, self).tearDown()
136 +
137  class TestArchiveDays(TestCaseInTempdir):
138      """make sure the 'days' option works"""
139      def setUp(self):
This page took 0.04325 seconds and 3 git commands to generate.