Mail::Qmail::Queue::Message - Send and/or receive a complete qmail-queue message.


Mail-Qmail-Queue documentation Contained in the Mail-Qmail-Queue distribution.

Index


Code Index:

NAME

Top

Mail::Qmail::Queue::Message - Send and/or receive a complete qmail-queue message.

SYNOPSIS

Top

  use Mail::Qmail::Queue::Send;

  # Read the message
  my $msg = Mail::Qmail::Queue::Message->receive()
    or die "Invalid message\n";

  # Change the from
  my $fr = $msg->from_ref();
  $$fr =~ s/\$/-\@[]/;   # Enable VERPs

  # Change the to
  my $to = $msg->to_ref();
  push(@$to,'GIFF@cpan.org');

  # Change the body
  my $br = $msg->body_ref();
  $$br =~ s/perl/Pathologically Eclectic Rubbish Lister/ig;

  # Now send
  $msg->send() == 0
    or die "Couldn't send message: Exit status $?\n";

DESCRIPTION

Top

This module handles mail messages sent and/or received by a program implementing the qmail-queue (qmail-queue(8)) interface.

You can create a message by providing the body and envelope to the constructor new (new), or from the file descriptors provided by the qmail-queue interface with the constructor receive (receive).

You can then modify the message and its envelope, if desired, by getting references to the various parts and modifying their referents.

Finally, you can send the message with the send (send) method.

CONSTRUCTORS

new ( $body, $from, @to )

Create a new mail message with the provided body, from, and to.

receive ( %options )

Receive a message with the qmail-queue (qmail-queue(8)) protocol.

This will read the entire message into memory; for very large messages and/or a lot of recipients, see Mail::Qmail::Queue::Send, Mail::Qmail::Queue::Receive::Envelope, and Mail::Qmail::Queue::Receive::Body.

Available options are:

EnvelopeFileHandle

Read the envelope from the provided FileHandle, instead of the default.

BodyFileHandle

Read the body from the provided FileHandle, instead of the default.

METHODS

send ( %options )

Send the message using the qmail-queue (qmail-queue(8)) protocol. The exit status from the qmail-queue program will be returned, so 0 indicates success. Valid options are the options for Mail::Qmail::Queue::Send->new.

from ( )

Get the from part of the envelope.

from_ref ( )

Get a reference to the from part of the envelope. By operating on this reference, you can change the value stored in this object.

to ( )

Get all to parts of the envelope.

to_ref ( )

Get a reference to the list of envelope to items. By modifying this list or its contents, you can change the values within this object.

body ( )

Get the body of the message.

body_ref ( )

Get a reference to the body of the message. By modifying this reference, you can change the value of the body within this object.

SEE ALSO

Top

qmail-queue(8), Mail::Qmail::Queue::Receive::Envelope, Mail::Qmail::Queue::Receive::Body, Mail::Qmail::Queue::Send.

COPYRIGHT

Top


Mail-Qmail-Queue documentation Contained in the Mail-Qmail-Queue distribution.
package Mail::Qmail::Queue::Message;
our $VERSION='0.02';
#
# Copyright 2006 Scott Gifford
#
# This library is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.

use Mail::Qmail::Queue::Error qw(:errcodes :fail);
use Mail::Qmail::Queue::Receive::Body;
use Mail::Qmail::Queue::Receive::Envelope;
use Mail::Qmail::Queue::Send;

sub new
{
    my $class = shift;
    my $self = bless {}, $class;
    ($self->{_body},$self->{_from},@{$self->{_to}})=@_;
    $self;
}

sub receive
{
    my $class = shift;
    my(%o) = @_;
    my(@qq_env_args,@qq_body_args);
    if ($o{EnvelopeFileHandle}) 
    {
	push(@qq_env_args,FileHandle => $o{EnvelopeFileHandle});
    }

    if ($o{BodyFileHandle})
    {
	push(@qq_body_args,FileHandle => $o{BodyFileHandle});
    }
    my $qq_env = Mail::Qmail::Queue::Receive::Envelope->new(@qq_env_args)
	or die "Couldn't get envelope reader: $!\n";
    my $qq_body = Mail::Qmail::Queue::Receive::Body->new(@qq_body_args)
	or die "Couldn't get body reader: $!\n";
    $class->new($qq_body->body,$qq_env->from,$qq_env->to);
}

sub send
{
    my $self = shift;
    my $qq_send = Mail::Qmail::Queue::Send->new(@_)
	or return undef;
    return $qq_send->send($self->body,$self->from,$self->to);
}

sub from
{
    my $self = shift;
    return $self->{_from};
}

sub from_ref
{
    my $self = shift;
    return \$self->{_from}
}

sub to
{
    my $self = shift;
    return @{$self->{_to}};
}

sub to_ref
{
    my $self = shift;
    return $self->{_to};
}

sub body
{
    my $self = shift;
    return $self->{_body};
}

sub body_ref
{
    my $self = shift;
    return \$self->{_body};
}


1;


1;