<!--
    $FML: queue.sgml,v 1.2 2005/07/20 10:39:17 fukachan Exp $
    $jaFML: queue.sgml,v 1.3 2003/04/15 14:51:37 fukachan Exp $
-->

<sect1 id="message.queue.incoming">
	<TITLE>
	Incoming Queuing
	</TITLE>

<para>
MTA kicks off a fml process. It reads a message from STDIN.
</para>

<para>
The fml process reads a message once and write it onto the hard disk
(write it into the incoming queue). After the queuing succeeded, the
process starts to analyze a message. For this logic, the original mail
is saved before main processing starts.
</para>

<para>
If the queuing fails, fml calls exit(EX_TEMPFAIL). In almost cases,
exit(75). If MTA receives this exit code, MTA tries to deliver again
later.
</para>

<para>
Mail::Delivery::Queue class processes the incoming queue.
The queus is removed when the process ends.
</para>

</sect1>


<sect1 id="message.queue.outgoing">
	<TITLE>
	fml Sends Back A Mail Message
	</TITLE>

<para>
Mail::Delivery::Queue class inserts a message to send back into the
mail queue. Later FML::Process::QueueManager handles the real delivery
process.
</para>

<para>
Article delivery processing is a little diffferent but based on
queueing by Mail::Delivery::Queue. If someting error occurs in
delivery, another fml process tries to deliver it later.
</para>


<sect2>
	<title>
	Coding In &fml8; Sources.
	</title>

<para>
Code is like this to send back a message:
<screen>
$curproc->reply_message( "you are not a ML member." );
</screen>
If no recipient specified, the recipient is the sender of the message
(From: address).
</para>


<para>
To send a file, like this:
<screen>
$curproc->reply_message( {
        type        => "text/plain; charset=iso-2022-jp",
        path        => "/etc/fml/main.cf",
        filename    => "main.cf",
        disposition => "main.cf example",
    });

$curproc->reply_message( {
        type        => "image/gif",
        path        => "/some/where/logo001.gif",
        filename    => "logo.gif",
        disposition => "attachment",
    });
</screen>
</para>

</sect2>

</sect1>


<sect1 id="message.queue">
	<TITLE>
	Mail Queue And Delivery System
	</TITLE>

<para>
FML::Process::QueueManager picks up one queue from the queue directory.
Mail::Message parses it.
Mail::Delivery processes the real delivery via FML::Mailer.
<screen>
Mail::Delivery::Queue
   |
   | ---> queue directory
   V
FML::Process::QueueManager
   |
   | <--- queue directory
   V
FML::Mailer
   |
   V
Mail::Delivery
</screen>
</para>

<para>
In manipulating queue, we should lock the target queue by flock(2).
</para>

</sect1>


<sect1>
	<TITLE>
	Mail Queue Directory
	</TITLE>

<para>
The queue directory consists of the following plural directories:
<screen>
new/
active/
incoming/
deferred/
info/sender/
info/recipients/
info/transport/
</screen>
info/ stores envelope information.
incoming/ holds incoming queue, others hold outgoing information.
</para>

<para>
In creating a new outgoing queue file, 
make a temporary file in new/ once.
When the delivery preparation is ended, 
move the queue from new/ to active/.
Hence files under active/ is delivery ready.
</para>

<sect2>
	<title>
	Lock The Queue
	</title>

<para>
When we need to handle the specific queue file,
use lock()/unlock() method for each $queue_id object.
The lock algorithm is based on flock(2) for the file.
</para>
</sect2>

</sect1>
