Mark Overmeer > HTML-FromMail > HTML::FromMail::Message

Download:
HTML-FromMail-0.11.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.11   Source  

NAME ^

HTML::FromMail::Message - output a message as HTML

INHERITANCE ^

 HTML::FromMail::Message
   is a HTML::FromMail::Page
   is a HTML::FromMail::Object
   is a Mail::Reporter

SYNOPSIS ^

DESCRIPTION ^

THIS MODULE IS UNDER CONSTRUCTION. However, a lot of things already work. Best take a look at the examples directory.

METHODS ^

$obj->createAttachment(MESSAGE, PART, ARGS)

Create an attachment file, and return a hash with information about that file. Returns undef if creation fails.

This method is used by htmlAttach() and htmlPreview() to create an actual attachment file. It defines url, size and type tags for the template.

 Option--Default
 outdir  <required>

. outdir => DIRECTORY

The name of the directory where the external file will be produced must be part of the ARGS hash.

$obj->disposition(MESSAGE, PART, ARGS)

Returns a string, which is either inline, attach, or preview, which indicates how the part of the message should be formatted. This can be changed with setting disposition.

$obj->fields

Returns the field text producing object.

$obj->header

Returns the header text producting object.

$obj->htmlAddresses(MESSAGE, ARGS)

Produce data about addresses which are in the field. This method uses HTML::FromMail::Field::htmlAddresses() for that.

$obj->htmlAttach

The attach container defines url, size and type tags for the template.

Example: using HTML::FromMail::Format::Magic

  <!--{message}-->
    <!--{attach}-->
    <!--{/attach}-->
  <!--{/message}-->

$obj->htmlBody(MESSAGE, ARGS)

Produce the body of a field. This tag can only be used inside a field container. See HTML::FromMail::Field::htmlBody() for the use and options.

$obj->htmlField(MESSAGE, ARGS)

Returns the field definition for the currently active message part. When the formatter sees this is a final token, then only the body of the field is returned (and the options of HTML::FromMail::Field::htmlBody() are accepted as well). Otherwise, the information about the field is captured to be used later.

 Option--Default
 decode  <true> if possible
 from    PART
 name    <required>

. decode => BOOLEAN

. from => PART|PARENT|MESSAGE

The source of this field: the currently active PART (which may be the main message), the PARENT of the active part (defaults to the message), or the main MESSAGE itself.

. name => STRING

Example: using HTML::FromMail::Format::Magic

  <!--{field name => To, content => REFOLD, wrap => 20}-->

  <!--{field name => To}-->
     <!--{name capitals => WELLFORMED}-->
     <!--{body wrap => 30}-->
  <!--{/field}-->

$obj->htmlForeachPart(MESSAGE, ARGS)

Produces html for the parts of a multipart mesasge body. Each part may be a multipart too. For each part, the message container code is applied recursively.

This container defines a part_number, and enables the use of the part tag.

Example: using HTML::FromMail::Format::Magic

  <!--{message}-->
    <!--{multipart}-->
      <ul>
      <!--{foreachPart}-->
      <li>This is part <!--{part_number}-->
          <!--{part}-->
      </li>
      <!--{/foreachPart}-->
      </ul>
    <!--{/multipart}-->
  <!--{message}-->

$obj->htmlHead(MESSAGE, ARGS)

Defines the fields of a header. The options are provided by HTML::FromMail::Head::fields().

Example: using HTML::FromMail::Format::Magic

 # simple
 <pre><!--{head}--></pre>

 # complex
 <table>
 <!--{head remove_spam_groups => 0}-->
   <tr><td><!--{name}--></td>
       <td><!--{body}--></td></tr>
 <!--{/head}-->
 </table>

$obj->htmlInline

 Option--Default
 type    ''

. type => MIME-TYPE

Selects the MIME types which are handled by this singlepart block. You can specify the types as defined by MIME::Type subroutine equal.

Example: using HTML::FromMail::Format::Magic

 <!--{message}-->
    <!--{inline type => text/html}-->
       <!--{html}-->
    <!--{/inline}-->
 <!--{/message}-->

$obj->htmlMessage(MESSAGE, ARGS)

Encapsulated code which is producing the message, which may be a multipart. You have to defined the message block when you use the part (see htmlPart()) tag. If you do not use that, you do not need this.

Example: using HTML::FromMail::Format::Magic

  <!--{message}-->
    <!--{inline}-->This is an inlined singlepart<!--{/inline}-->
    <!--{attach}-->This is an attachment<!--{/attach}-->
    <!--{preview}-->An attachment with preview<!--{/preview}-->
    <!--{multipart}-->This is a multipart<!--{/multipart}-->
    <!--{nested}-->message/rfc822 encapsulated<!--{/nested}-->
  <!--{/message}-->

$obj->htmlMultipart(MESSAGE, ARGS)

Encapsulates text to be produced when the message(-part) is a multipart.

$obj->htmlName(MESSAGE, ARGS)

Produce the name of a field. This tag can only be used inside a field container. See HTML::FromMail::Field::htmlName() for the use and options.

$obj->htmlNested(MESSAGE, ARGS)

Contains text to be produced when the message(-part) is a nested message; encapsulated in a message/rfc822.

$obj->htmlPart(MESSAGE, ARGS)

Apply the message container of the current part on its data. See example in htmlForeachPart().

$obj->htmlPreview

 Option--Default
 type    ''

. type => MIME-TYPE

Selects the MIME types which are handled by this singlepart block. You can specify the types as defined by MIME::Type subroutine equal.

The preview container defines url, size and type tags for the template, which describe the attachment file. Besides, it preview defines a tag which tells whether the preview is made as html or as image. Within an html block, you will get an extra text which includes the actual html preview text.

The image container provides more tags: smallurl, smallwidth, smallheight, width, and height.

Example: using HTML::FromMail::Format::Magic

  <!--{message}-->
    <!--{preview}-->
       <!--{html}-->
          <!--{text}-->
       <!--{/html}-->
       <!--{image}-->
          <img src="<!--{smallurl}-->"
           width="<!--{smallwidth}-->"
           height="<!--{smallheight}-->"><br />
           (real is <!--{width}--> x <!--{height}-->)
       <!--{/image}-->
       <a href="<!--{url}-->">Attachment of
        <!--{type}--> (<!--{size}--> bytes)</a>
    <!--{/preview}-->
  <!--{/message}-->

$obj->htmlRawText(MESSAGE, ARGS)

Returns the plain text of the body.

$obj->htmlSubject(MESSAGE, ARGS)

Get the subject field from the message's header, just a short-cut for specifying htmlField(name) with subject.

Example: using HTML::FromMail::Format::Magic

  <!--{subject}-->                # message subject
  <!--{field name => subject}-->  # part's subject
  <!--{field name => subject, from => MESSAGE}-->  # message subject

$obj->htmlifier(MIME-TYPE)

Returns the code reference for a routine which can create html for the objects of the specified MIME-TYPE. The TYPE may be a (smartly overloaded) MIME::Type object. The behaviour can be changed with the htmlifiers setting.

$obj->lookup(LABEL, ARGS)

See "METHODS" in HTML::FromMail::Page

HTML::FromMail::Message->new(OPTIONS)

 Option  --Defined in     --Default
 settings  HTML::FromMail::Object  {}
 topic     HTML::FromMail::Object  'message'

. settings => HASH-OF-HASHES

. topic => STRING

$obj->previewer(MIME-TYPE)

Returns the code reference for a routine which can create a preview for the objects of the specified MIME-TYPE. The TYPE may be a (smartly overloaded) MIME::Type object. The behaviour can be changed with the previewers setting.

Attributes

$obj->settings([TOPIC])

See "Attributes" in HTML::FromMail::Object

$obj->topic

See "Attributes" in HTML::FromMail::Object

Export

Other methods

$obj->plain2html(STRING)

See "Other methods" in HTML::FromMail::Object

DETAILS ^

Settings

You can specify the following settings in HTML::FromMail::new(settings) for topic message:

disposition CODE

Message parts have to be displayed. There are a few ways to do that: by inline, attach, and preview. In the first case, the text of the part is inserted in the main page, in the other two as link to an external file. The latter is creating a small preview of the attachement.

The message may provide an indication of the way the part should be displayed in the Content-Disposition field. For many reasons, an exception will be made... for instance, binary messages will never be inlined. You can create your own code reference to change the behavior of the default algorithm.

Example: of own disposition rules

 my $f = HTML::FromMail->new
  ( settings =>
      { message => { disposition => \&my_disposer }
      }
  );

 sub my_disposer($$$$$)
 {   my ($obj, $message, $part, $suggestion, $args) = @_;

     return 'attach'
        if $suggestion eq 'inline' && $part->size > 10_000;
     $suggestion;
 }

previewers ARRAY-OF-PAIRS

For some kinds of message parts, previews can be produced. This ordered list of PAIRS contains mime type with code reference combinations, each describing such a production. The specified items are added before the default list of preview generators. An undef as code reference will cause the default preview producer to be disabled.

Method previewer() is called when a previewer for a certain content type has to be looked-up. The default previewers are defined (and implemented) in HTML::FromMail::Default::Previewers.

htmlifiers ARRAY-OF-PAIRS

Some kinds of information can be translated into HTML. When a data type defines such a translation, it may be inlined (see htmlInline()), where in other cases it will get attached. The usage is the same as for the previewers option.

Method htmlifier() is called when a htmlifier for a certain content type has to be looked-up. The default htmlifiers are defined (and implemented) in HTML::FromMail::Default::HTMLifiers.

Example: use own converters

 my @prevs = ( 'text/postscript' => \&prepost
             , 'image'           => \&imagemagick
             );
 my @html  = ( 'text/html'       => \&strip_html
             , 'text/plain'      => \&plain2html
             );

 my $f = HTML::FromMail->new
  ( settings =>
      { message => { previewers  => \@prevs
                   , htmlifiers  => \@html
                   , disposition => \&my_disposer
                   }
      }
  );

 sub prepost($$$$$)
 {   my ($page, $message, $part, $attach, $args) = @_;
     # args contains extra info from template
     # returns a hash of info which is used in a
     # preview block (see htmlPreview())
 }

DIAGNOSTICS ^

Error: No field name specified in $template

Error: foreachPart not used within part

Error: foreachPart outside multipart

Error: use of 'addresses' outside field container

Error: use of 'body' outside field container

Error: use of 'name' outside field container

SEE ALSO ^

This module is part of HTML-FromMail distribution version 0.11, built on June 08, 2007. Website: http://perl.overmeer.net/html-from-mail/

LICENSE ^

Copyrights 2003,2004,2007 by Mark Overmeer. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html

syntax highlighting: