File: takelarge.pl

package info (click to toggle)
libmail-box-perl 2.068-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,576 kB
  • ctags: 1,493
  • sloc: perl: 22,358; makefile: 49
file content (71 lines) | stat: -rw-r--r-- 1,684 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl

# Demonstrates how to select some messages from one folder, and move
# them to a different folder.  In this case, the first argument is
# the existing folder, the second will contain the messages larger
# than the specified size:
#
#       takelarge.pl infolder outfolder minsize

# *******************************************************************
# * WARNING: the content of infolder will be reduced!!! Don't do this
# *          on your real folders.... it's only a demo
# *******************************************************************

# This code can be used and modified without restriction.
# Mark Overmeer, <mailbox@overmeer.net>, 9 nov 2001

use warnings;
use strict;
use lib '..', '.';

use Mail::Box::Manager 2.00;

#
# Get the command line arguments.
#

die "Usage: $0 folder-from folder-to size\n"
    unless @ARGV==3;

my ($infile, $outfile, $size) = @ARGV;

#
# Open the folder
#

my $mgr    = Mail::Box::Manager->new;

my $inbox  = $mgr->open
  ( $infile
  , access    => 'rw'      # to update deleted
  , extract   => 'ALWAYS'  # read all bodies immediately: faster
  );

die "Cannot open $infile to read: $!\n"
    unless defined $inbox;

my $outbox = $mgr->open
  ( $outfile
  , access   => 'a'        # append,
  , create   => 1          # create if not existent
  );

die "Cannot open $outfile to write: $!\n"
    unless defined $outbox;

foreach my $message ($inbox->messages)
{   next if $message->size < $size;

    $mgr->moveMessage($outbox, $message);
    print 'Moved "',$message->get('Subject') || '<no subject>'
       ,  '": ', $message->size, " bytes.\n";
}

#
# Finish
#

#$inbox->close;
#$outbox->close;
$mgr->closeAllFolders;