~ubuntu-branches/ubuntu/vivid/libpostfix-parse-mailq-perl/vivid

« back to all changes in this revision

Viewing changes to lib/Postfix/Parse/Mailq.pm

  • Committer: Package Import Robot
  • Author(s): Florian Schlichting, Ansgar Burchardt, Salvatore Bonaccorso, Axel Beckert, Florian Schlichting
  • Date: 2013-09-27 00:06:26 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130927000626-0tubjo9zcj5u5m40
Tags: 1.002-1
[ Ansgar Burchardt ]
* debian/control: Convert Vcs-* fields to Git.

[ Salvatore Bonaccorso ]
* Change Vcs-Git to canonical URI (git://anonscm.debian.org)
* Change search.cpan.org based URIs to metacpan.org based URIs

[ Axel Beckert ]
* debian/copyright: migrate pre-1.0 format to 1.0 using "cme fix dpkg-
  copyright"

[ Florian Schlichting ]
* Import Upstream version 1.002
* Bump year of upstream copyright
* Update stand-alone License paragraphs
* Bump dh compatibility to level 8 (no changes necessary)
* Add a build-dependency on Test::More 0.96
* Declare compliance with Debian Policy 3.9.4
* Switch to source format 3.0 (quilt)
* Add myself to uploaders and copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
use strict;
2
2
use warnings;
3
3
package Postfix::Parse::Mailq;
4
 
our $VERSION = '1.001';
5
 
 
 
4
{
 
5
  $Postfix::Parse::Mailq::VERSION = '1.002';
 
6
}
6
7
use Mixin::Linewise::Readers -readers;
7
8
# ABSTRACT: parse the output of the postfix mailq command
8
9
 
54
55
 
55
56
  chomp @$block;
56
57
  my $first = shift @$block;
57
 
  my $error = $block->[0] =~ /\A\S/ ? (shift @$block) : undef;
 
58
  my $error = defined $block->[0] && $block->[0] =~ /\A\S/
 
59
            ? (shift @$block)
 
60
            : undef;
58
61
  my @dest  = map { s/^\s+//; $_; } @$block;
59
62
 
60
63
  my ($qid, $status_chr, $size, $date, $sender) = $first =~ m/
95
98
 
96
99
=head1 VERSION
97
100
 
98
 
version 1.001
 
101
version 1.002
99
102
 
100
103
=head1 SYNOPSIS
101
104
 
102
 
    use Postfix::Parse::Mailq;
103
 
 
104
 
    my $mailq_output = `mailq`;
105
 
    my $entries = Postfix::Parse::Mailq->read_string($mailq_output);
106
 
 
107
 
    my $bytes = 0;
108
 
    for my $entry (@$entries) {
109
 
      next unless grep { /\@aol.com$/ } @{ $entry->{remaining_rcpts} };
110
 
      $bytes += $entry->{size};
111
 
    }
112
 
    
113
 
    print "$bytes bytes remain to send to AOL destinations\n";
114
 
 
115
 
=head1 WARNING
116
 
 
117
 
This code is really rough and the interface will change.  Entries will be
118
 
objects.  There will be some more methods.  Still, the basics are likely to
119
 
keep working, or keep pretty close to what you see here now.
 
105
  use Postfix::Parse::Mailq;
 
106
 
 
107
  my $mailq_output = `mailq`;
 
108
  my $entries = Postfix::Parse::Mailq->read_string($mailq_output);
 
109
 
 
110
  my $bytes = 0;
 
111
  for my $entry (@$entries) {
 
112
    next unless grep { /\@aol.com$/ } @{ $entry->{remaining_rcpts} };
 
113
    $bytes += $entry->{size};
 
114
  }
 
115
  
 
116
  print "$bytes bytes remain to send to AOL destinations\n";
120
117
 
121
118
=head1 METHODS
122
119
 
126
123
 
127
124
=head2 read_string
128
125
 
129
 
    my $entries = Postfix::Parse::Mailq->read_string($string, \%arg);
 
126
  my $entries = Postfix::Parse::Mailq->read_string($string, \%arg);
130
127
 
131
128
This methods read the output of postfix's F<mailq> from a file (by name), a
132
129
filehandle, or a string, respectively.  They return an arrayref of hashrefs,
134
131
 
135
132
Valid arguments are:
136
133
 
137
 
    spool - a hashref of { queue_id -> spool_name } pairs
138
 
            if given, this will be used to attempt to indicate in which
139
 
            spool messages currently are; it is not entirely reliable (race!)
 
134
  spool - a hashref of { queue_id -> spool_name } pairs
 
135
          if given, this will be used to attempt to indicate in which
 
136
          spool messages currently are; it is not entirely reliable (race!)
140
137
 
141
138
=head2 parse_block
142
139
 
143
 
    my $entry = Mailq->parse_block(\@lines);
 
140
  my $entry = Mailq->parse_block(\@lines);
144
141
 
145
142
Given all the lines in a single entry's block of lines in mailq output, this
146
143
returns data about the entry.
147
144
 
 
145
=head1 WARNING
 
146
 
 
147
This code is really rough and the interface will change.  Entries will be
 
148
objects.  There will be some more methods.  Still, the basics are likely to
 
149
keep working, or keep pretty close to what you see here now.
 
150
 
148
151
=head1 AUTHOR
149
152
 
150
 
  Ricardo SIGNES <rjbs@cpan.org>
 
153
Ricardo SIGNES <rjbs@cpan.org>
151
154
 
152
155
=head1 COPYRIGHT AND LICENSE
153
156
 
154
 
This software is copyright (c) 2008 by Ricardo SIGNES.
 
157
This software is copyright (c) 2013 by Ricardo SIGNES.
155
158
 
156
159
This is free software; you can redistribute it and/or modify it under
157
 
the same terms as perl itself.
158
 
 
159
 
=cut 
160
 
 
161
 
 
 
160
the same terms as the Perl 5 programming language system itself.
 
161
 
 
162
=cut