my Mail::Message $forward = $message->forward(To => 'you'); $forward->send;
Complex functionality on Mail::Message objects is implemented in different files which are autoloaded. This file implements the functionality related to creating forwarded messages.
The main difference between bounce() and forward() is the reason for message processing. The bounce has no intention to modify the content of message: the same information is passed-on to someplace else. This may mean some conversions, but for instance, the Message-ID does not need to be changed.
The purpose of forward() is to pass on information which is modified: annotated or reduced. The information is not sent back to the author of the original message (which is implemented by reply()), but to someone else.
So: some information comes in, is modified, and than forwarded to someone else. Currently, there are four ways to get the original information included, which are explained in the next sections.
After the creation of the forward, you may want to rebuild() the message to remove unnecessary complexities. Of course, that is not required.
When you specify forward(body), you have created your own body object to
be used as content of the forwarded message. This implies that
forward(include) is 'NO'
: no automatic generation of the forwarded
body.
The forward(include) is set to 'INLINE'
(the default)
This is the most complicated situation, but most often used by MUAs:
the original message is inserted textually in the new body. You can
set-up automatic stripping of signatures, the way of encapsulation,
and texts which should be added before and after the encapsulated part.
However, the result may not always be what you expect. For instance, some people use very long signatures which will not be automatically stripped because the pass the threshold. So, you probably need some manual intervention after the message is created and before it is sent.
When a binary message is encountered, inlining is impossible. In that
case, the message is treated as if 'ENCAPSULATE'
was requested.
When forward(include) is explicitly set to 'ATTACH'
the result
will be a multipart which contains two parts. The first part will
be your message, and the second the body of the original message.
This means that the headers of the forwarded message are used for
the new message, and detached from the part which now contains the
original body information. Content related headers will (of course)
still be part of that part, but lines line To
and Subject
will
not be stored with that part.
As example of the structural transformation:
# code: $original->printStructure; multipart/alternative: The source message text/plain: content in raw text text/html: content as html # code: $fwd = $original->forward(include => 'ATTACH'); # code: $fwd->printStructure multipart/mixed: The source message text/plain: prelude/postlude/signature multipart/alternative text/plain: content in raw text text/html: content as html
When forward(include) is explicitly set to 'ENCAPSULATE'
, then
the original message is left in-tact as good as possible. The lines
of the original message are used in the main message header but also
enclosed in the part header.
The encapsulation is implemented using a nested message, content type
message/rfc822
. As example of the structural transformation:
# code: $original->printStructure; multipart/alternative: The source message text/plain: content in raw text text/html: content as html # code: $fwd = $original->forward(include => 'ENCAPSULATE'); # code: $fwd->printStructure multipart/mixed: The source message text/plain: prelude/postlude/signature message/rfc822 multipart/alternative: The source message text/plain: content in raw text text/html: content as html
The message structure is much more complex, but no information is lost. This is probably the reason why many MUAs use this when the forward an original message as attachment.