| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | |
|---|
| 5 | BEGIN { chdir 't' if -d 't' } |
|---|
| 6 | use lib '../lib'; |
|---|
| 7 | |
|---|
| 8 | use Test::More tests => 9; |
|---|
| 9 | use File::Path; |
|---|
| 10 | use File::Basename; |
|---|
| 11 | |
|---|
| 12 | use Lancelot::DB; |
|---|
| 13 | use Lancelot::Template; |
|---|
| 14 | use Lancelot::Message; |
|---|
| 15 | use Lancelot::Log; |
|---|
| 16 | |
|---|
| 17 | use Lancelot::Module::archive_store; |
|---|
| 18 | |
|---|
| 19 | sub copy_msg { |
|---|
| 20 | return Lancelot::Message->new($_[0]->as_string); |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | BEGIN { use_ok('Lancelot::Digest::plain'); } |
|---|
| 24 | |
|---|
| 25 | my $listname = 'pl-testlist@example.com'; |
|---|
| 26 | |
|---|
| 27 | rmtree("$ENV{HOME}/.pl/$listname", 0); |
|---|
| 28 | |
|---|
| 29 | my $db = new Lancelot::DB $listname, { create => 1 }; |
|---|
| 30 | $db->set_config('list.name', 'Pl-testlist'); |
|---|
| 31 | |
|---|
| 32 | # Fake an archive of messages to prepare a digest from |
|---|
| 33 | |
|---|
| 34 | for (my $i = 1; $i <= 10; $i++) { |
|---|
| 35 | my $msg = Lancelot::Message->new(sprintf 'From: hugo@example.com |
|---|
| 36 | To: pl-testlist@example.com |
|---|
| 37 | Subject: Test %u |
|---|
| 38 | Date: Mon, 12 May 2008 12:00:%02u +0200 |
|---|
| 39 | |
|---|
| 40 | This is test message %u. |
|---|
| 41 | ', $i % 3, $i, $i); |
|---|
| 42 | Lancelot::Module::archive_store::execute($db, $msg); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | # Test the digest builder |
|---|
| 46 | |
|---|
| 47 | my $ok = q|Date: \w{3}, \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]\d{4} |
|---|
| 48 | MIME-Version: 1.0 |
|---|
| 49 | From: pl-testlist\+digest@example.com |
|---|
| 50 | Reply-To: pl-testlist@example.com |
|---|
| 51 | To: pl-testlist@example.com |
|---|
| 52 | Subject: Pl-testlist Digest V1 #1 |
|---|
| 53 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 54 | |
|---|
| 55 | Pl-testlist Digest\s{9,10}\w{3}, \d{1,2} \w{3} \d{4}\s{9,10}Volume 1 : Issue 1 |
|---|
| 56 | |
|---|
| 57 | Today's Topics: |
|---|
| 58 | |
|---|
| 59 | Test 1 |
|---|
| 60 | |
|---|
| 61 | ---------------------------------------------------------------------- |
|---|
| 62 | |
|---|
| 63 | Date: Mon, 12 May 2008 12:00:01 \+0200 |
|---|
| 64 | From: hugo@example.com |
|---|
| 65 | To: pl-testlist@example.com |
|---|
| 66 | Subject: Test 1 |
|---|
| 67 | |
|---|
| 68 | This is test message 1. |
|---|
| 69 | |
|---|
| 70 | ------------------------------ |
|---|
| 71 | |
|---|
| 72 | End of Pl-testlist Digest V1 Issue #1 |
|---|
| 73 | \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* |
|---|
| 74 | |; |
|---|
| 75 | |
|---|
| 76 | my $digest = Lancelot::Digest::plain::build($db, 1, 1, [1 .. 1]); |
|---|
| 77 | my $s; ($s = $digest->as_string) =~ s/\r//g; |
|---|
| 78 | like($s, qr/$ok/, 'basic digest match'); |
|---|
| 79 | |
|---|
| 80 | # Two messages, different subjects |
|---|
| 81 | |
|---|
| 82 | $ok = q|Date: \w{3}, \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]\d{4} |
|---|
| 83 | MIME-Version: 1.0 |
|---|
| 84 | From: pl-testlist\+digest@example.com |
|---|
| 85 | Reply-To: pl-testlist@example.com |
|---|
| 86 | To: pl-testlist@example.com |
|---|
| 87 | Subject: Pl-testlist Digest V1 #1 |
|---|
| 88 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 89 | |
|---|
| 90 | Pl-testlist Digest\s{9,10}\w{3}, \d{1,2} \w{3} \d{4}\s{9,10}Volume 1 : Issue 1 |
|---|
| 91 | |
|---|
| 92 | Today's Topics: |
|---|
| 93 | |
|---|
| 94 | Test 1 |
|---|
| 95 | Test 2 |
|---|
| 96 | |
|---|
| 97 | ---------------------------------------------------------------------- |
|---|
| 98 | |
|---|
| 99 | Date: Mon, 12 May 2008 12:00:01 \+0200 |
|---|
| 100 | From: hugo@example.com |
|---|
| 101 | To: pl-testlist@example.com |
|---|
| 102 | Subject: Test 1 |
|---|
| 103 | |
|---|
| 104 | This is test message 1. |
|---|
| 105 | |
|---|
| 106 | ------------------------------ |
|---|
| 107 | |
|---|
| 108 | Date: Mon, 12 May 2008 12:00:02 \+0200 |
|---|
| 109 | From: hugo@example.com |
|---|
| 110 | To: pl-testlist@example.com |
|---|
| 111 | Subject: Test 2 |
|---|
| 112 | |
|---|
| 113 | This is test message 2. |
|---|
| 114 | |
|---|
| 115 | ------------------------------ |
|---|
| 116 | |
|---|
| 117 | End of Pl-testlist Digest V1 Issue #1 |
|---|
| 118 | \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* |
|---|
| 119 | |; |
|---|
| 120 | |
|---|
| 121 | $digest = Lancelot::Digest::plain::build($db, 1, 1, [1 .. 2]); |
|---|
| 122 | ($s = $digest->as_string) =~ s/\r//g; |
|---|
| 123 | like($s, qr/$ok/, 'basic digest match (2 messages, 2 topics)'); |
|---|
| 124 | |
|---|
| 125 | $ok = q|Date: \w{3}, \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]\d{4} |
|---|
| 126 | MIME-Version: 1.0 |
|---|
| 127 | From: pl-testlist\+digest@example.com |
|---|
| 128 | Reply-To: pl-testlist@example.com |
|---|
| 129 | To: pl-testlist@example.com |
|---|
| 130 | Subject: Pl-testlist Digest V1 #1 |
|---|
| 131 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 132 | |
|---|
| 133 | Pl-testlist Digest\s{9,10}\w{3}, \d{1,2} \w{3} \d{4}\s{9,10}Volume 1 : Issue 1 |
|---|
| 134 | |
|---|
| 135 | Today's Topics: |
|---|
| 136 | |
|---|
| 137 | Test 1 |
|---|
| 138 | |
|---|
| 139 | ---------------------------------------------------------------------- |
|---|
| 140 | |
|---|
| 141 | Date: Mon, 12 May 2008 12:00:01 \+0200 |
|---|
| 142 | From: hugo@example.com |
|---|
| 143 | To: pl-testlist@example.com |
|---|
| 144 | Subject: Test 1 |
|---|
| 145 | |
|---|
| 146 | This is test message 1. |
|---|
| 147 | |
|---|
| 148 | ------------------------------ |
|---|
| 149 | |
|---|
| 150 | Date: Mon, 12 May 2008 12:00:04 \+0200 |
|---|
| 151 | From: hugo@example.com |
|---|
| 152 | To: pl-testlist@example.com |
|---|
| 153 | Subject: Test 1 |
|---|
| 154 | |
|---|
| 155 | This is test message 4. |
|---|
| 156 | |
|---|
| 157 | ------------------------------ |
|---|
| 158 | |
|---|
| 159 | End of Pl-testlist Digest V1 Issue #1 |
|---|
| 160 | \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* |
|---|
| 161 | |; |
|---|
| 162 | |
|---|
| 163 | $digest = Lancelot::Digest::plain::build($db, 1, 1, [1, 4]); |
|---|
| 164 | ($s = $digest->as_string) =~ s/\r//g; |
|---|
| 165 | like($s, qr/$ok/, 'basic digest match (disjoint, 2 messages, 1 topic)'); |
|---|
| 166 | |
|---|
| 167 | # Various odds and ends for condition coverage |
|---|
| 168 | |
|---|
| 169 | # Games with mail.delimiter |
|---|
| 170 | |
|---|
| 171 | $db->delete_configs('mail.delimiter'); |
|---|
| 172 | |
|---|
| 173 | $ok = q|Date: \w{3}, \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]\d{4} |
|---|
| 174 | MIME-Version: 1.0 |
|---|
| 175 | From: pl-testlist-digest@example.com |
|---|
| 176 | Reply-To: pl-testlist@example.com |
|---|
| 177 | To: pl-testlist@example.com |
|---|
| 178 | Subject: Pl-testlist Digest V1 #1 |
|---|
| 179 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 180 | |
|---|
| 181 | Pl-testlist Digest\s{9,10}\w{3}, \d{1,2} \w{3} \d{4}\s{9,10}Volume 1 : Issue 1 |
|---|
| 182 | |
|---|
| 183 | Today's Topics: |
|---|
| 184 | |
|---|
| 185 | Test 1 |
|---|
| 186 | |
|---|
| 187 | ---------------------------------------------------------------------- |
|---|
| 188 | |
|---|
| 189 | Date: Mon, 12 May 2008 12:00:01 \+0200 |
|---|
| 190 | From: hugo@example.com |
|---|
| 191 | To: pl-testlist@example.com |
|---|
| 192 | Subject: Test 1 |
|---|
| 193 | |
|---|
| 194 | This is test message 1. |
|---|
| 195 | |
|---|
| 196 | ------------------------------ |
|---|
| 197 | |
|---|
| 198 | End of Pl-testlist Digest V1 Issue #1 |
|---|
| 199 | \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* |
|---|
| 200 | |; |
|---|
| 201 | |
|---|
| 202 | $digest = Lancelot::Digest::plain::build($db, 1, 1, [1 .. 1]); |
|---|
| 203 | ($s = $digest->as_string) =~ s/\r//g; |
|---|
| 204 | like($s, qr/$ok/, 'basic digest match (default mail delimiter)'); |
|---|
| 205 | |
|---|
| 206 | $db->set_config('mail.delimiter', '+'); |
|---|
| 207 | |
|---|
| 208 | $ok = q|Date: \w{3}, \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]\d{4} |
|---|
| 209 | MIME-Version: 1.0 |
|---|
| 210 | From: pl-testlist\+digest@example.com |
|---|
| 211 | Reply-To: pl-testlist@example.com |
|---|
| 212 | To: pl-testlist@example.com |
|---|
| 213 | Subject: Pl-testlist Digest V1 #1 |
|---|
| 214 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 215 | |
|---|
| 216 | Pl-testlist Digest\s{9,10}\w{3}, \d{1,2} \w{3} \d{4}\s{9,10}Volume 1 : Issue 1 |
|---|
| 217 | |
|---|
| 218 | Today's Topics: |
|---|
| 219 | |
|---|
| 220 | Test 1 |
|---|
| 221 | |
|---|
| 222 | ---------------------------------------------------------------------- |
|---|
| 223 | |
|---|
| 224 | Date: Mon, 12 May 2008 12:00:01 \+0200 |
|---|
| 225 | From: hugo@example.com |
|---|
| 226 | To: pl-testlist@example.com |
|---|
| 227 | Subject: Test 1 |
|---|
| 228 | |
|---|
| 229 | This is test message 1. |
|---|
| 230 | |
|---|
| 231 | ------------------------------ |
|---|
| 232 | |
|---|
| 233 | End of Pl-testlist Digest V1 Issue #1 |
|---|
| 234 | \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* |
|---|
| 235 | |; |
|---|
| 236 | |
|---|
| 237 | $digest = Lancelot::Digest::plain::build($db, 1, 1, [1 .. 1]); |
|---|
| 238 | ($s = $digest->as_string) =~ s/\r//g; |
|---|
| 239 | like($s, qr/$ok/, 'basic digest match (different mail delimiter)'); |
|---|
| 240 | |
|---|
| 241 | # Different digest.name |
|---|
| 242 | |
|---|
| 243 | $db->delete_configs('mail.delimiter'); |
|---|
| 244 | $db->set_config('digest.name', 'The Indigestion Digest'); |
|---|
| 245 | |
|---|
| 246 | $ok = q|Date: \w{3}, \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]\d{4} |
|---|
| 247 | MIME-Version: 1.0 |
|---|
| 248 | From: pl-testlist-digest@example.com |
|---|
| 249 | Reply-To: pl-testlist@example.com |
|---|
| 250 | To: pl-testlist@example.com |
|---|
| 251 | Subject: The Indigestion Digest V1 #1 |
|---|
| 252 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 253 | |
|---|
| 254 | The Indigestion Digest\s{7,8}\w{3}, \d{1,2} \w{3} \d{4}\s{7,8}Volume 1 : Issue 1 |
|---|
| 255 | |
|---|
| 256 | Today's Topics: |
|---|
| 257 | |
|---|
| 258 | Test 1 |
|---|
| 259 | |
|---|
| 260 | ---------------------------------------------------------------------- |
|---|
| 261 | |
|---|
| 262 | Date: Mon, 12 May 2008 12:00:01 \+0200 |
|---|
| 263 | From: hugo@example.com |
|---|
| 264 | To: pl-testlist@example.com |
|---|
| 265 | Subject: Test 1 |
|---|
| 266 | |
|---|
| 267 | This is test message 1. |
|---|
| 268 | |
|---|
| 269 | ------------------------------ |
|---|
| 270 | |
|---|
| 271 | End of The Indigestion Digest V1 Issue #1 |
|---|
| 272 | \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* |
|---|
| 273 | |; |
|---|
| 274 | |
|---|
| 275 | $digest = Lancelot::Digest::plain::build($db, 1, 1, [1 .. 1]); |
|---|
| 276 | ($s = $digest->as_string) =~ s/\r//g; |
|---|
| 277 | like($s, qr/$ok/, 'digest match (non-default digest.name)'); |
|---|
| 278 | |
|---|
| 279 | # archive.directory stuff |
|---|
| 280 | |
|---|
| 281 | $db->delete_configs('digest.name', 'archive.directory'); |
|---|
| 282 | |
|---|
| 283 | $ok = q|Date: \w{3}, \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]\d{4} |
|---|
| 284 | MIME-Version: 1.0 |
|---|
| 285 | From: pl-testlist-digest@example.com |
|---|
| 286 | Reply-To: pl-testlist@example.com |
|---|
| 287 | To: pl-testlist@example.com |
|---|
| 288 | Subject: Pl-testlist Digest V1 #1 |
|---|
| 289 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 290 | |
|---|
| 291 | Pl-testlist Digest\s{9,10}\w{3}, \d{1,2} \w{3} \d{4}\s{9,10}Volume 1 : Issue 1 |
|---|
| 292 | |
|---|
| 293 | Today's Topics: |
|---|
| 294 | |
|---|
| 295 | Test 1 |
|---|
| 296 | |
|---|
| 297 | ---------------------------------------------------------------------- |
|---|
| 298 | |
|---|
| 299 | Date: Mon, 12 May 2008 12:00:01 \+0200 |
|---|
| 300 | From: hugo@example.com |
|---|
| 301 | To: pl-testlist@example.com |
|---|
| 302 | Subject: Test 1 |
|---|
| 303 | |
|---|
| 304 | This is test message 1. |
|---|
| 305 | |
|---|
| 306 | ------------------------------ |
|---|
| 307 | |
|---|
| 308 | End of Pl-testlist Digest V1 Issue #1 |
|---|
| 309 | \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* |
|---|
| 310 | |; |
|---|
| 311 | |
|---|
| 312 | $digest = Lancelot::Digest::plain::build($db, 1, 1, [1 .. 1]); |
|---|
| 313 | ($s = $digest->as_string) =~ s/\r//g; |
|---|
| 314 | like($s, qr/$ok/, 'basic digest match (unset archive.directory)'); |
|---|
| 315 | |
|---|
| 316 | my $adir = "$ENV{HOME}/.pl/$listname/archive"; |
|---|
| 317 | $db->set_config('archive.directory', $adir); |
|---|
| 318 | |
|---|
| 319 | $digest = Lancelot::Digest::plain::build($db, 1, 1, [1 .. 1]); |
|---|
| 320 | ($s = $digest->as_string) =~ s/\r//g; |
|---|
| 321 | like($s, qr/$ok/, 'basic digest match (absolute-path archive.directory)'); |
|---|
| 322 | |
|---|