<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.    
-->
<document>

 <properties>
  <title>James 2.1 - Configuring FetchPOP</title>
 </properties>

<body>
<section name="FetchPOP Is Being Deprecated">
<p>FetchPOP is being deprecated.
<a href="fetchmail_configuration_2_2.html">fetchMail</a> provides a superset of
FetchPOP's functionality and is the preferred solution.</p>
</section>

<section name="FetchPOP Configuration">
<p>FetchPOP is controlled by a configuration block in the config.xml.
The fetchpop tag defines the boundaries of the configuration block.  It encloses 
all the relevant configuration for the FetchPOP scheduler.  The behavior of the POP service is
controlled by the attributes and children of this tag.</p>
<p>This tag has an optional boolean attribute - <strong>enabled</strong> - that defines whether 
the service is active or not.  The value defaults to "false" if not present.</p>
<p>The only permitted children of the fetchpop tag are <strong>fetch</strong> elements.  Each of 
these <strong>fetch</strong> tags defines a single FetchPOP task.</p>
<p>The <strong>fetch</strong> tag has a single required attribute, <strong>name</strong>.  The name 
of each FetchPOP task must be unique.</p>
<p>In addition to the <strong>name</strong> attribute, the <strong>fetch</strong> tag has four 
children, all of which are required.</p>
<ul>
<li><strong>host</strong> - The host name or IP address of the POP3 server hosting the mail to be fetched.</li>
<li><strong>user</strong> - The user name of the account whose mail is to be fetched.</li>
<li><strong>password</strong> - The password for the account whose mail is to be fetched.</li>
<li><strong>interval</strong> - A non-negative integer representing the number of milliseconds between fetches.</li>
</ul>
</section>
<section name="Considerations When Handling Fetched Mail">
<p>There are a number of issues which have to be considered when handling fetched mail, such as avoiding circular
routing of mail.  Some scenarios are described below with suggested configurations.</p>

<subsection name="Handling All Mail for a Domain">
<p>This is the intended primary use of FetchPOP.
If all mail for a domain being fetched is ultimately being handled by this server then it is enough to add
the domain name as a servername to the servernames section described <a href="serverwide_configuration_2_1.html">here</a>.
<br/>This is the simplest solution and is used where James is being used to redistribute all mail from the
free catch-all POP accounts provided by many domain registration/hosting companies.</p>
</subsection>
<subsection name="Handling a Subset of a Domain's Mail">
<p>If only part of a domain's mail (perhaps only a single user's POP account) is being handled by this instance
of James it is important that outgoing mail addressed to this domain that is not intended for James be properly delivered.</p>
<p>To enable this filtering the FetchPOP scheduler adds a header, X-fetchedby, to the fetched message.  This header can be checked using
the provided matcher <b>FetchedFrom</b>.  This matcher can be used to direct fetched mail to a processor set up 
to handle mail fetched from one or more POP3 accounts.  The matcher should be used exactly once in the mail 
pipeline for each FetchPOP task, as the matcher removes a matching header to prevent outgoing replies or 
redirections from looping.</p>
<p>The FetchedFrom matcher is configured with the name of the particular FetchPOP task it is supposed to match.  In general,
this matcher will be used to direct mail to a custom processor for further processing.  A mailet tag such as the 
following</p>
<source>
&lt;mailet match="FetchedFrom=<i>fetchtaskname</i>" class="ToProcessor"&gt;<br/>
&lt;processor&gt;<i>fetchprocessor</i>&lt;/processor&gt;
&lt;/mailet&gt;
</source>
<p>where <i>fetchtaskname</i> is the name of the FetchPOP task being matched and <i>fetchprocessor</i> is the name of the fetched mail 
processor can be used to this purpose.  The fetched mail processor should contain mailets which will filter 
and forward mail to real local or remote users.  This can be achieved in the usual fashion as described in the 
<a href="spoolmanager_configuration_2_1.html">SpoolManager configuration section</a> and in the out of the box 
configuration file.</p>
</subsection>
 <subsection name="Catching Undeliverable Mail">
<p>It is important to note that this first version of FetchPOP does not access the original intended recipient
address of the mail, but instead uses the <b>To:</b> address from the message headers.  Since this header may contain an
alias for the intended recipient, or may never have contained the intended recipient address (it could have been 
in the Cc: or Bcc: fields) it is possible that James will be unable to deliver the fetched mail.  It is intended 
that this behaviour be addressed in the next version of James, but in the meantime a catch-all forwarding of 
locally undeliverable fetched mail is recommended.</p>
<p>To handle messages where the intended recipient can be determined but is not present in the To: header, the FetchedFrom 
matcher can be used.  Place a mailet tag with this matcher between the "RecipientIsLocal" and "HostIsLocal" in the 
Transport processor as defined in the out of the box configuration.  The mailet tag should be configured to use the 
provided ToProcessor mailet to direct fetched mail to a custom processor.  Thus all mail fetched by FetchPOP that 
could not be trivially mapped to a local user account will undergo further processing, allowing more complex
delivery handling.</p>
<p>For safety the All matcher should be used at the end of your custom fetched mail processor.  This can be used to 
catch all mail not handled by previous mailets in the processor.  This will enable you to ensure that your 
configuration is correct and that any mail not correctly delivered is available for examination by the postmaster.</p>
</subsection>
</section>
</body>
</document>
