<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
    <!ENTITY rfc1035 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.1035.xml'>
    <!ENTITY rfc1123 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.1123.xml'>
    <!ENTITY rfc2034 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2034.xml'>
    <!ENTITY rfc2119 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
    <!ENTITY rfc2181 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2181.xml'>
    <!ENTITY rfc2234 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2234.xml'>
    <!ENTITY rfc2396 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2396.xml'>
    <!ENTITY rfc2821 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2821.xml'>
    <!ENTITY rfc2822 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2822.xml'>
    <!ENTITY rfc3513 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3513.xml'>

    <!ENTITY rfc1034 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.1034.xml'>
    <!ENTITY rfc1983 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.1983.xml'>
    <!ENTITY rfc2162 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2162.xml'>
    <!ENTITY rfc3696 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3696.xml'>
    <!ENTITY rfc3833 PUBLIC '' 
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3833.xml'>

]>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>

<?rfc toc="yes" ?>
<?rfc tocindent="yes" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="no"?>
<?rfc iprnotified="no" ?>
<?rfc strict="yes" ?>
<?rfc autobreaks="yes" ?>
<rfc docName="draft-schlitt-spf-classic-00" ipr="full3667">
  <front>
    <title abbrev="Sender Policy Framework (SPF)">
      Sender Policy Framework: Authorizing Use of Domains in E-MAIL
    </title>
<!--
    <author fullname="Mark Lentczner" initials="M." surname="Lentczner">
      <organization/>
      <address>
        <postal>
          <street>1209 Villa Street</street>
          <city>Mountain View</city>
          <region>CA</region>
          <code>94041</code>
          <country>United States of America</country>
        </postal>
        <email>markl@glyphic.com</email>
        <uri>http://www.ozonehouse.com/mark/</uri>
      </address>
    </author>
-->
    <author fullname="Meng Weng Wong" initials="M. W." surname="Wong">
      <organization/>
      <address>
        <postal>
          <street/>
          <country>Singapore</country>
        </postal>
        <email>mengwong+spf@pobox.com</email>
        <uri>http://spf.pobox.com/</uri>
      </address>
    </author>
    <author fullname="Wayne Schlitt" initials="W." surname="Schlitt">
      <organization/>
      <address>
        <postal>
          <street>4615 Meredeth #9</street>
          <city>Lincoln Nebraska</city>
          <region>NE</region>
          <code>68506</code>
          <country>United States of America</country>
        </postal>
        <email>wayne@schlitt.net</email>
        <uri>http://www.schlitt.net/spf/</uri>
      </address>
    </author>
    <date month="December" day="30" year="2004"/>
    <workgroup>Network Working Group</workgroup>
    <abstract>
      <t>
        E-mail on the Internet can be forged in a number of ways.  In
        particular, existing protocols place no restriction in what a sending
        host can use as the reverse-path of a message.  This document
        describes a protocol whereby a domain can explicitly authorize the
        hosts that are allowed to use its domain name in a reverse-path, and
        a way for receiving hosts to check such authorization.
      </t>
    </abstract>
  </front>
  <middle>
    <section anchor="intro" title="Introduction">
      <t>
        The current e-mail infrastructure has the property that any host
        injecting mail into the mail system can identify itself as any domain
        name it wants.  Hosts can do this at a variety of levels: in
        particular, the session, the envelope, and the mail headers.  While
        this feature is desirable in some circumstances, it is a major
        obstacle to reducing end-user unwanted e-mail (or "spam").
        Furthermore, many domain name holders are understandably concerned
        about the ease with which other entities may make use of their domain
        names, often with intent to impersonate.
      </t>
      <t>
        This document defines a protocol by which domain owners may
        authorize hosts to use their domain name in the "MAIL FROM" or
        "HELO" identity.  Compliant domain holders publish SPF records
        about which hosts are permitted to use their names, and
        compliant mail receivers use the published SPF records to test
        the authorization of hosts using a given "HELO" or "MAIL FROM"
        identity during a mail transaction.
      </t>
      <t>
        An additional benefit to mail receivers is that when the use of an
        identity is verified, then local policy decisions about the mail can
        be made on the basis of the domain, rather than the host's IP
        address.  This is advantageous because reputation of domain names is
        likely to be more accurate than reputation of host IP addresses.
        Furthermore, if a claimed identity fails verification, then local
        policy can take stronger action against such e-mail, such as
        rejecting it.
      </t>
      <section title="Protocol Status">
        <t>
          SPF has been in development since the Summer of 2003, and
          has seen deployment beyond the developers beginning in
          December, 2003.  The design of SPF slowly evolved until the
          spring of 2004 and has since stabilized. There have been
          quite a number of forms of SPF, some written up as
          documents, some submitted as Internet Drafts, and many
          discussed and debated in development forums.
        </t>
        <t>
          The goal of this document is to clearly document the
          protocol defined by earlier drafts specifications of SPF as
          used in existing implementations.  This conception of SPF is
          sometimes called "SPF Classic".  It is understood that
          particular implementations and deployments may differ from,
          and build upon, this work.  It is hoped that we have
          nonetheless captured the common understanding of SPF version
          1.
        </t>
      </section>
      <section title="Terminology">
        <t>
          The key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
          "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY",
          and "OPTIONAL" in this document are to be interpreted as
          described in <xref target="RFC2119"/>.
        </t>
        <t>
          This document is concerned with a portion of a mail message
          commonly called "envelope sender", "return path", "reverse
          path", "bounce address", "2821 FROM", or "MAIL FROM".  Since
          these terms are either not well defined, or often used
          casually, this document defines the "MAIL FROM" identity in
          <xref target="mfrom-ident"/>.  Note that other terms, that
          may superficially look like the common terms, such as
          "reverse-path", are used only with the defined meanings from
          normative documents.
        </t>
      </section>
    </section>
    <section title="Operation">
      <section title="The HELO Identity" anchor="helo-ident">
        <t>
          The "HELO" identity derives from either the SMTP HELO or
          EHLO command (see <xref target="RFC2821"/>.) These commands
          supply the SMTP client (sender) for the SMTP session.  Note
          that requirements for the domain presented in the EHLO or
          HELO command are not always clear to the sending party, and
          SPF client must be prepared for the "HELO" identity to be
          malformed.
        </t>
        <t>
          SPF clients MAY check the "HELO" identity by calling the
          check_host() function (<xref target="function"/>) with the
          "HELO" identity as the &lt;sender&gt;.  If the HELO test
          returns a "fail", the overall result for the SMTP session is
          "fail", and there is no need to test the "MAIL FROM" identity.
        </t>
      </section>
      <section title="The MAIL FROM Identity" anchor="mfrom-ident">
        <t>
          The "MAIL FROM" identity derives from the SMTP MAIL command
          (see <xref target="RFC2821" />.) This command supplies the
          "reverse-path" for a message, which generally consists of
          the sender mailbox, and is the mailbox to which notification
          messages are sent if there are problems delivering the
          message.
        </t>
        <t>
          <xref target="RFC2821" /> allows the reverse-path to be null
          (see Section 4.5.5.) In this case, there is no explicit
          sender mailbox, and such a message can be assumed to be a
          notification message from the mail system itself.  When the
          reverse-path is null, this document defines the "MAIL FROM"
          identity to be the mailbox composed of the localpart
          "postmaster" and the "HELO" identity
        </t>
        <t>
          SPF clients MUST check the "MAIL FROM" identity unless HELO
          testing produced a "fail".  SPF clients check the "MAIL
          FROM" identity by calling the check_host() function with the
          "MAIL FROM" identity as the &lt;sender&gt;.
        </t>
      </section>
      <section title="Publishing Authorization">
        <t>
          An SPF compliant domain MUST publish a valid SPF record as
          described in <xref target="records"/>.  This record
          authorizes the use of the domain name in the "HELO" and/or
          "MAIL FROM" identity, by some sending MTAs, and not by
          others.
        </t>
        <t>
          It is RECOMMENDED that domains publish SPF records that end
          in "-all", or redirect to other records that do, so that a
          definitive determination of authorization can be made.
        </t>
        <t>
          Domain holders may publish SPF records that explicitly
          authorize no hosts for domain names that shouldn't be used
          in sender mailboxes.
        </t>
      </section>
      <section title="Checking Authorization">
        <t>
          A mail receiver can perform an SPF compliant check for each
          mail message it receives.  This check tests the
          authorization of a client host to inject mail with a given
          "MAIL FROM" identity.  This check MAY also be applied to the
          "HELO" identity.  Typically, such checks are done by a
          receiving MTA, but can be performed elsewhere in the mail
          processing chain so long as the required information is
          available. Checking other identities against SPF records is
          NOT RECOMMENDED because there are cases that are known to
          give incorrect results.
        </t>
        <t>
          It is possible that mail receivers will use the SPF check as
          part of a larger set of tests on incoming mail.  The results
          of other tests may influence whether or not a particular SPF
          check is performed.  For example, finding the sending host
          on a local white list may cause all other tests to be
          skipped and all mail from that host to be accepted.
        </t>
        <t>
          When a mail receiver decides to perform an SPF check, it
          MUST implement and evaluate the check_host() function (<xref
          target="function"/>) correctly.  While the test as a whole
          is optional, once it has been decided to perform a test it
          must be performed as specified so that the correct semantics
          are preserved between publisher and receiver.
        </t>
        <t>
          To make the test, the mail receiver MUST evaluate the
          check_host() with the arguments set as follows:
        </t>
        <t>
          <list style="hanging" hangIndent="9">
            <t hangText="&lt;ip&gt;">- the IP address of the SMTP client
              that is injecting the mail, either IPv4 or IPv6.
            </t>
            <t hangText="&lt;domain&gt;">- the domain portion of the
              "MAIL FROM" or "HELO" identity.
            </t>
            <t hangText="&lt;sender&gt;">- the "MAIL FROM" or "HELO"
              identity.
            </t>
          </list>
        </t>
        <t>
          Note that the &lt;domain&gt; argument may not be a well
          formed domain name.  For example, if the reverse-path was
          null, then the EHLO or HELO domain is used.  In a valid SMTP
          session, this can be an address literal or entirely
          malformed.  In these cases, check_host() is defined in <xref
          target="initial" /> to return a "None" result.
          <!-- FIXME: should this be "None"? lots of conflict between -->
          <!-- PermError in the various specs and implementations -->  
        </t>
        <t>
          Care must be taken to correctly extract the &lt;domain&gt;
          from the &lt;sender&gt; as many MTAs will still accept such
          things as source routes (see <xref target="RFC2821"/>
          appendix C), the percent hack (see <xref target="RFC2162"/>)
          and bang paths (see <xref target="RFC1983"/>).  These
          archaic features have been maliciously used to bypass
          security systems.
        </t>
        <t>
          Software SHOULD perform this authorization check during the
          processing of the SMTP transaction that injects the mail.
          This allows errors to be returned directly to the injecting
          server by way of SMTP replies.  Software can perform the
          check as early as the MAIL command, though it may be easier
          to delay the check to some later stage of the transaction.
        </t>
        <t>
          Software can perform the authorization after the
          corresponding SMTP transaction has completed.  There are two
          problems with this approach: 1) It may be difficult to
          accurately extract all the required information such as
          client IP address and HELO domain name.  2) If the
          authorization fails, then generating a non-delivery
          notification to the alleged sender is problematic due to the
          large number of forged emails on the Internet today.  Such
          an action would go against the explicit wishes of the
          alleged sender.
        </t>
      </section>
      <section title="Interpreting the Result" anchor="op-result">
        <t>
          The check_host() function returns one of seven results.
          This section describes how software that performs the
          authorization must interpret the results.  If the check is
          being performed during the SMTP mail transaction, it also
          describes how to respond.
        </t>
        <section title="None">
          <t>
            A result of None means that no records were published by
            the domain.  The checking software cannot ascertain if the
            client host is authorized or not.
          </t>
        </section>
        <section title="Neutral">
          <t>
            The domain owner has explicitly stated that doesn't know
            whether the IP is authorized or not.  A Neutral result
            MUST be treated exactly like the None result.
          </t>
        </section>
        <section title="Pass">
          <t>
            A Pass result means that the client is authorized to
            inject mail with the given identity.  Further
            policy checks, such as reputation, or black and/or white
            listing, can now proceed with confidence in the identity.
          </t>
        </section>
        <section title="Fail" anchor="op-result-fail">
          <t>
            A Fail result is an explicit statement that the client is
            not authorized to use the domain in the given
            identity.  The checking software can choose to mark the
            mail based on this, or to reject the mail outright.
          </t>
          <t>
            If the checking software chooses to reject the mail during
            the SMTP transaction, then it SHOULD use an SMTP reply
            code of 550 (see <xref target="RFC2821"/>) and, if
            supported, the 5.7.1 DSN code (see <xref
            target="RFC2034"/>), in addition to an appropriate
            message.  The check_host() function may return either a
            default explanation string, or one from the domain that
            published the SPF records (see <xref target="mod-exp"/>).
            If the information doesn't originate with the checking
            software, it should be made clear that text is not
            trusted.  For example:
          </t>
          <figure>
            <artwork>
    550-5.7.1 SPF MAIL FROM check failed: 
    550-5.7.1 The domain example.com explains:
    550 5.7.1 Please see http://www.example.com/mailpolicy.html
            </artwork>
          </figure>
        </section>
        <section title="SoftFail">
          <t>
            A SoftFail result should be treated as somewhere between a
            Fail and a Neutral.  The domain believes the host isn't
            authorized but isn't willing to make that strong of a
            statement.  Receiving software SHOULD NOT reject the
            message based on this result, but MAY subject the message
            to closer scrutiny.
          </t>
          <t>
            Since the domain has discouraged the use of this host,
            receivers MAY try to inform either the sender or the
            recipient of the e-mail.  As examples, the recipient's MUA
            could highlight the SoftFail status.  Or the MTA could
            give the sender a message using a technique called
            "greylisting" where by the MTA can issue an SMTP reply
            code of 451 (4.3.0 DSN code) with a note the first time
            the message was received, but accept it the second time.
          </t>
        </section>
        <section title="TempError">
          <t>
            A TempError result means that the SPF client encountered a
            transient error when performing the check.  Checking
            software can choose to accept or temporarily reject the
            message.  If the message is rejected during the SMTP
            transaction for this reason, the software SHOULD use an
            SMTP reply code of 451 and, if supported, the 4.4.3 DSN
            code.
          </t>
        </section>
        <section title="PermError">
          <t>
            A PermError result means that the domain's published
            records couldn't be correctly interpreted.  Checking
            software SHOULD reject the message.  If rejecting during
            SMTP transaction time, it SHOULD use an SMTP reply code of
            550 and, if supported, the 5.5.2 DSN code.
          </t>
        </section>
      </section>
    </section>
    <section title="SPF Records" anchor="records">
      <t>
        An SPF record declares which hosts are, and are not,
        authorized to use a domain name for the "HELO" or "MAIL FROM"
        identity. Loosely, the record partitions all hosts into
        permitted and not-permitted sets. (Though some hosts might
        fall into neither category.)
      </t>
      <t>
        The SPF record is a single string of text. An example record is:
      </t>
      <t>
        <list>
          <t>v=spf1 +mx a:colo.example.com/28 -all</t>
        </list>
      </t>
      <t>
        This record has a version of "v=spf1" and three directives:
        "+mx", "a:colo.example.com/28" (the + is implied), and "-all".
      </t>
      <section title="Publishing" anchor="publishing">
        <t>
          Domain owners wishing to be SPF compliant must publish SPF
          records for the hosts that are used in both the MAIL FROM
          and HELO identities.  The SPF records are placed in the DNS
          tree at the host name it pertains to, not a subdomain under
          it, such as is done with SRV records.  This is the same
          whether TXT RRs or SPF RRs are used.
        </t>
        <t>
          The example above in <xref target="records"/> might be
          published easily via this lines in a domain zone file:
        </t>
        <t>
          <list>
            <t>example.com.          IN TXT "v=spf1 +mx a:colo.example.com/28 -all"</t>
            <t>smtp-out.example.com. IN TXT "v=spf1 a -all"</t>
          </list>
        </t>
        <t>
          When publishing via TXT records, beware of other TXT records
          published there for other purposes.  They may cause problems
          with size limits (see <xref target="rsize"/>.)
        </t>
        <t>
          An SPF record published at the zone cut for the domain will
          be used as a default for all subdomains within the zone (See
          <xref target="version"/>.) Domain owners SHOULD publish SPF
          records for hosts used for the HELO and MAIL FROM identities
          instead of using the zone cut default because the fallback
          requires additional DNS lookups.  The zone cut default does
          reduce the need to publish SPF records for non-email related
          hosts, such as www.example.com.
        </t>
        <section title="DNS Resource Record Types">
          <t>
            This document defines a new DNS Resource Record (RR) of
            type SPF, type code to be determined. The format of this
            type is identical to the TXT RR <xref target="RFC1035"/>.
            For either type, the character content of the record is
            encoded as US-ASCII.
          </t>
          <t>
            It is recognized that the current practice (using a TXT
            record) is not optimal, but it is necessary because
            there are a number of DNS server and resolver
            implementations in common use that cannot handle the new
            RR type.  The two record type scheme provides a forward
            path to the better solution of using a RR type reserved
            for this purpose.
          </t>
          <t>
            An SPF compliant domain name SHOULD have SPF records of
            both RR types. A compliant domain name MUST have a record
            of at least one type. If a domain has records of both
            types, they MUST have identical content.  For example,
            instead of just publishing one record as in <xref
            target="publishing"/> above, it is better to publish:
            <figure>
              <artwork>
   example.com. IN TXT "v=spf1 +mx a:colo.example.com/28 -all"
   example.com. IN SPF "v=spf1 +mx a:colo.example.com/28 -all"
              </artwork>
            </figure>
          </t>
          <t>
            An SPF compliant check SHOULD lookup both types. Lookups
            can be performed serially or in parallel. If both types of
            records are obtained for a domain, the SPF type MUST be
            used.
          </t>
          <t>
            Example RRs in this document are shown with the TXT record
            type, however they could also be published with both RR types.
          </t>
        </section>
        <section title="Multiple Records">
          <t>
            A domain name MUST NOT have multiple records that would
            cause an authorization check to select more than one
            record. See <xref target="version"/> for the selection
            rules.
          </t>
        </section>
        <section title="Multiple Strings">
          <t>
            A text DNS record (either TXT and SPF RR types) can be
            composed of more than one string. If a published record
            contains multiple strings, then the record MUST be treated
            as if those strings are concatenated together without
            adding spaces. For example:
          </t>
          <t>
            <list style="empty">
              <t>IN TXT "v=spf1 .... first" "second string..."</t>
            </list>
          </t>
          <t>MUST be treated as equivalent to</t>
          <t>
            <list style="empty">
              <t>IN TXT "v=spf1 .... firstsecond string..."</t>
            </list>
          </t>
          <t>
            SPF or TXT records containing multiple strings are useful
            in order to construct longer records which would otherwise
            exceed the maximum length of a string within a TXT or SPF
            RR record.
          </t>
        </section>
        <section title="Record Size" anchor="rsize">
          <t>
            The published SPF record for a given domain name SHOULD
            remain small enough that the results of a query for it
            will fit within 512 octets.  This will keep even older DNS
            implementations from falling over to TCP.  Since the
            answer size is dependent on many things outside the scope
            of this document, it is only possible to give this
            guideline: If the combined length of the DNS name and the
            text of all the records of a given type (TXT or SPF) is
            under 450 characters, then DNS answers should fit in UDP
            packets.  Note that when computing the sizes for queries
            of the TXT format, one must take into account any other
            TXT records published at the domain name.  Records that
            are too long to fit in a single UDP packet MAY be
            silently ignored. 
          </t>
        </section>
        <section title="Wildcard Records">
          <t>
            Use of wildcard records for publishing is not
            recommended. Care must be taken if wildcard records are
            used. If a domain publishes wildcard MX records, it may want
            to publish wildcard declarations, subject to the same
            requirements and problems. In particular, the declaration
            must be repeated for any host that has any RR records at
            all, and for subdomains thereof. For example, the example
            given in <xref target="RFC1034"/>, Section 4.3.3, could be
            extended with:
            <figure>
              <artwork>
    X.COM.          MX      10      A.X.COM
    X.COM.          TXT     "v=spf1 a:A.X.COM -all"
    
    *.X.COM.        MX      10      A.X.COM
    *.X.COM.        TXT     "v=spf1 a:A.X.COM -all"
                    
    A.X.COM.        A       1.2.3.4
    A.X.COM.        MX      10      A.X.COM
    A.X.COM.        TXT     "v=spf1 a:A.X.COM -all"
                    
    *.A.X.COM.      MX      10      A.X.COM
    *.A.X.COM.      TXT     "v=spf1 a:A.X.COM -all"
              </artwork>
            </figure>
          </t>
          <t>
            Notice that SPF records must be repeated twice for every
            name within the domain: Once for the name, and once with a
            wildcard to cover the tree under the name.
          </t>
          <t>
            Use of wildcards is discouraged in general as they cause every
            name under the domain to exist and queries against arbitrary names
            will never return RCODE 3 (Name Error). 
          </t>
        </section>
      </section>
    </section>
    <section title="The check_host() Function" anchor="function">
      <t>
        The check_host() function fetches SPF records, parses them,
        and interprets them to evaluate if a particular host is or is
        not permitted to send mail with a given 
        identity. Mail receivers that perform this check MUST
        correctly evaluate the check_host() function as described here.
      </t>
      <t>
        Implementations MAY use a different algorithm than the canonical
        algorithm defined here, so long as the results are the same.
      </t>
      <section title="Arguments">
        <t>The function check_host() takes these arguments: </t>
        <t>
          <list style="hanging" hangIndent="9">
            <t hangText="&lt;ip&gt;">- the IP address of the SMTP client
              that is injecting the mail, either IPv4 or IPv6.
            </t>
            <t hangText="&lt;domain&gt;">- the domain portion of the
              "MAIL FROM" or "HELO" identity.
            </t>
            <t hangText="&lt;sender&gt;">- the "MAIL FROM" or "HELO"
              identity.
            </t>
          </list>
        </t>
        <t>
          The domain portion of &lt;sender&gt; will usually be the
          same as the &lt;domain&gt; argument when check_host() is
          initially evaluated. However, it will generally not be true for
          recursive evaluations (see <xref target="mech-include"/>
          below).
        </t>
        <t>
          Actual implementations of the check_host() function will
          likely need additional arguments.
          </t>
      </section>
      <section title="Results">
        <t>
          The function check_host() can result in one of seven results
          described in <xref target="op-result"/>. Based on the
          result, the action to be taken is determined by the local
          policies of the receiver.
        </t>
      </section>
      <section title="Initial Processing" anchor="initial">
        <t>
          If the &lt;domain&gt; is malformed or is not a fully
          qualified domain name, check_host() immediately returns the
          result "None".
        </t>
        <t>
          If the &lt;sender&gt; has no localpart, substitute the
          string "postmaster" for the localpart. 
        </t>
      </section>
      <section title="Record Lookup">
        <t>
          In accordance with how the records are published, see <xref
          target="publishing"/> above, a DNS query needs to be made
          for the &lt;domain&gt; name, querying for either RR type
          TXT, SPF or both.
        </t>
        <t>
          If the DNS lookup returns a server failure (RCODE 2), or
          other error (RCODE other than 0 or 3), or the query times
          out, check_host() exits immediately with the result
          "TempError"
        </t>
      </section>
      <section title="Selecting Records" anchor="version">
        <t> Records begin with a version section:</t>
        <figure>
          <artwork type="abnf">
record           = version terms *SP
version          = "v=spf1"
          </artwork>
        </figure>
        <t>
          Starting with the set of records that were returned by the lookup,
          record selection proceeds in two steps: 
        </t>
        <t>
          <list style="numbers">
            <t>
              If any records of type SPF are in the set, then all
              records of type TXT are discarded.
            </t>
            <t>
              Records that do not begin with a version section of
              exactly "v=spf1" are discarded.  Note that the version
              section is terminated either by a SP character or the
              end of the record.  A record with a version section of
              "v=spf10" does not match and must be discarded.
            </t>
          </list>
        </t>
        <t>
          After the above steps, there should be exactly one record
          remaining and evaluation can proceed. If there are two or
          more records remaining, then check_host() exits immediately
          with the result of "PermError".
        </t>
        <t>
          If no matching records are returned for the &lt;domain;&gt;,
          the SPF client MUST find the Zone Cut as defined in <xref
          target="RFC2181" /> section 6 and repeat the above steps.
          The &lt;domain&gt;'s zone origin is then searched for SPF
          records.  If an SPF record is found at the zone origin, the
          &lt;domain&gt; is set to the zone origin as if a "redirect"
          modifier was executed.
        </t>
        <t>
          If no matching records are returned for either search, an SPF
          client MUST assume that the domain makes no SPF declarations.  SPF
          processing MUST abort and return "None".
        </t>
      </section>
      <section title="Record Evaluation">
        <t>
          After one SPF record has been selected, the check_host()
          function parses and interprets it to find a result for the
          current test. If there are any syntax errors, check_host()
          returns immediately with the result "PermError".
        </t>
        <t>
          Implementations MAY choose to parse the entire record first
          and return "PermError" if the record is not syntactically
          well formed.  However, in all cases, any syntax errors
          anywhere in the record MUST be detected.
        </t>
        <section title="Term Evaluation">
          <t>
            There are two types of terms: mechanisms and modifiers.  A
            record contains an ordered list of these as specified in
            the following ABNF.
          </t>
          <figure>
            <artwork type="abnf">
terms            = *( 1*SP ( directive / modifier ) )

directive        = [ prefix ] mechanism
prefix           = "+" / "-" / "?" / "~"
mechanism        = ( all / include
                   / A / MX / PTR / IP4 / IP6 / exists )

modifier         = redirect / explanation / unknown-modifier
unknown-modifier = name "=" macro-string

name             = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." )
            </artwork>
          </figure>
          <t> Most mechanisms allow a ":" or "/" character after the name. </t>
          <t>
            Modifiers always contain an equals ('=') character immediately
            after the name, and before any ":" or "/" characters that may be
            part of the macro-string. 
          </t>
          <t> Terms that do not contain any of "=", ":" or "/" are mechanisms. </t>
          <t>
            As per the definition of the ABNF notation in <xref
            target="RFC2234"/>, mechanism and modifier names are
            case-insensitive.
          </t>
        </section>
        <section title="Mechanisms">
          <t>
            Each mechanism is considered in turn from left to
            right. If there are no more mechanisms, the result is
            specified in <xref target="default"/>.
          </t>
          <t>
            When a mechanism is evaluated, one of three things can
            happen: it can match, it can not match, or it can throw an
            exception. 
          </t>
          <t>
            If it matches, processing ends and the prefix value is
            returned as the result of that record.  If it does not
            match, processing continues with the next mechanism.  If
            it throws an exception, mechanism processing ends and the
            exception value is returned.
          </t>
          <t>
            The possible prefixes, and the results they return are:
            <list style="hanging">
              <t hangText="&quot;+&quot;">Pass</t>
              <t hangText="&quot;-&quot;">Fail</t>
              <t hangText="&quot;~&quot;">SoftFail</t>
              <t hangText="&quot;?&quot;">Neutral</t>
            </list>
          </t>
          <t> The prefix is optional and defaults to "+". </t>
          <t>
            When a mechanism matches, and the prefix is "-" so that a
            "Fail" result is returned and the explanation string is
            computed as described in <xref target="mod-exp"/>.
          </t>
          <t> Specific mechanisms are described in <xref target="mechanisms"/>. </t>
        </section>
        <section title="Modifiers">
          <t>
            Modifiers are not mechanisms: they do not return match or
            not-match.  Instead they provide additional information.
            While modifiers do not directly effect the evaluation of
            the record, the "redirect" modifier has an effect after
            all the mechanisms have been evaluated.
          </t>
        </section>
      </section>
      <section title="Default Result" anchor="default">
        <t>
          If none of the mechanisms match and there is no "redirect"
          modifier, then the check_host() returns a result of
          "Neutral". If there is a "redirect" modifier, check_host()
          proceeds as defined in <xref target="mod-redirect"/>.
        </t>
        <t>
          Note that records SHOULD always either use a "redirect" modifier or an
          "all" mechanism to explicitly terminate processing. 
        </t>
        <t> For example: </t>
        <t>
          <list style="empty">
            <t>v=spf1 +mx -all</t>
          </list> or <list style="empty">
            <t>v=spf1 +mx redirect=_spf.example.com</t>
          </list>
        </t>
      </section>
      <section title="Domain Specification">
        <t>
          Several of these mechanisms and modifiers have a
          &lt;domain-spec&gt; section. The &lt;domain-spec&gt;
          string is macro expanded (see <xref target="macros"/>). The resulting
          string is the common presentation form of a fully qualified DNS name:
          A series of labels separated by periods. This domain is called the
          &lt;target-name&gt; in the rest of this document. 
        </t>
        <t>
          Note: The result of the macro expansion is not subject to
          any further escaping. Hence, this facility cannot produce
          all characters that are legal in a DNS label (e.g.  the
          control characters).  However, this facility is powerful
          enough to express legal host names, and common utility
          labels (such as "_spf") that are used in DNS.
        </t>
        <t>
          For several mechanisms, the &lt;domain-spec&gt; is optional. If it is
          not provided, the &lt;domain&gt; is used as the
          &lt;target-name&gt;. 
        </t>
      </section>
    </section>
    <section title="Mechanism Definitions" anchor="mechanisms">
      <t> This section defines two types of mechanisms. </t>
      <t>
        Basic mechanisms contribute to the language framework. They do not
        specify a particular type of authorization scheme. 
      </t>
      <t>
        <list style="empty">
          <t>all</t>
          <t>include</t>
        </list>
      </t>
      <t>
        Designated sender mechanisms are used to designate a set of
        &lt;ip&gt; addresses as being permitted or not to use the
        &lt;domain&gt; for sending mail. 
      </t>
      <t>
        <list style="empty">
          <t>a</t>
          <t>mx</t>
          <t>ptr</t>
          <t>ip4</t>
          <t>ip6</t>
          <t>exists</t>
        </list>
      </t>
      <t>
        The following conventions apply to all mechanisms that perform a
        comparison between &lt;ip&gt; and an IP address at any point: 
      </t>
      <t>
        If no CIDR-length is given in the directive, then &lt;ip&gt;
        and the IP address are compared for equality. 
      </t>
      <t>
        If a CIDR-length is specified, then only the specified number of
        high-order bits of &lt;ip&gt; and the IP address are compared
        for equality. 
      </t>
      <t>
        When any mechanism fetches host addresses to compare with
        &lt;ip&gt;, when &lt;ip&gt; is an IPv4 address, A records are
        fetched, when &lt;ip&gt; is an IPv6 address, AAAA records are
        fetched.  Even if the SMTP connection is via IPv6, an
        IPv4-mapped IPv6 IP address (see <xref target="RFC3513"/>
        section 2.5.5) MUST still be considered an IPv4 address.
      </t>
      <t>
        Several mechanisms rely on information fetched from DNS.  For
        these DNS queries, except where noted, if the DNS server
        returns an error (RCODE other than 0 or 3) or the query times
        out, the mechanism throws the exception "TempError".  If the
        server returns "domain does not exist" (RCODE 3), then
        evaluation of the mechanism continues as if the server
        returned no error (RCODE 0) and zero answer records.
      </t>
      <section title="&quot;all&quot;" anchor="mech-all">
        <figure>
          <artwork type="abnf">
all              = "all"
          </artwork>
        </figure>
        <t>
          The "all" mechanism is a test that always matches. It is used as the
          rightmost mechanism in a record to provide an explicit default. 
        </t>
        <t> For example: <list style="empty">
            <t> v=spf1 a mx -all </t>
          </list>
        </t>
        <t>
          Mechanisms after "all" will never be tested. Any "redirect"
          modifier (<xref target="mod-redirect"/>) has no effect when
          there is an "all" mechanism.
        </t>
      </section>
      <section title="&quot;include&quot;" anchor="mech-include">
        <figure>
          <artwork type="abnf">
include          = "include"  ":" domain-spec
          </artwork>
        </figure>
        <t>
          The "include" mechanism triggers a recursive evaluation of
          check_host(). The domain-spec is expanded as per <xref
          target="macros"/>. Then check_host() is evaluated with the
          resulting string as the &lt;domain&gt;. The &lt;ip&gt; and
          &lt;sender&gt; arguments remain the same as in the current
          evaluation of check_host().  
        </t>
        <t>
          In hind sight, the name "include" was poorly chosen.  Only
          the evaluated results of the referenced SPF record is used,
          rather than acting as if the referenced SPF record was
          literally included in the first. Better names for this
          mechanism would have been something like "on-pass" or
          "if-pass".
        </t>
        <t>
          The "include" mechanism makes it possible for one domain to
          designate multiple administratively independent domains.
          For example, a vanity domain "example.net" might send mail
          using the servers of administratively independent domains
          example.com and example.org.
        </t>
        <t> Example.net could say </t>
        <t>
          <list style="empty">
            <t> "v=spf1 include:example.com include:example.org -all". </t>
          </list>
        </t>
        <t>
          That would direct check_host() to, in effect, check the
          records of example.com and example.org for a "pass"
          result. Only if the host were not permitted for either of
          those domains would the result be "Fail".
        </t>
        <t>
          Whether this mechanism matches or not, or throws an error
          depends on the result of the recursive evaluation of
          check_host():
        </t>
        <texttable>
          <ttcol>A recursive check_host() result of:</ttcol>
          <ttcol>Causes the "include" mechanism to:</ttcol>
          <c>Pass</c>
          <c>match</c>
          <c>Fail</c>
          <c>not match</c>
          <c>SoftFail</c>
          <c>not match</c>
          <c>Neutral</c>
          <c>not match</c>
          <c>TempError</c>
          <c>throw TempError</c>
          <c>PermError</c>
          <c>throw PermError</c>
          <c>None</c>
          <c>throw PermError</c>
        </texttable>
        <t>
          The "include" mechanism is intended for crossing
          administrative boundaries. While it is possible to use
          includes to consolidate multiple domains that share the same
          set of designated hosts, domains are encouraged to use
          redirects where possible, and to minimize the number of
          includes within a single administrative domain. For example,
          if example.com and example.org were managed by the same
          entity, and if the permitted set of hosts for both domains
          were "mx:example.com", it would be possible for example.org
          to specify "include:example.com", but it would be preferable
          to specify "redirect=example.com" or even "mx:example.com".
        </t>
      </section>
      <section title="&quot;a&quot;" anchor="mech-a">
        <t>
          This mechanism matches if &lt;ip&gt; is one of the
          &lt;target-name&gt;'s IP addresses. 
        </t>
        <figure>
          <artwork type="abnf">
A                = "a"      [ ":" domain-spec ] [ dual-cidr-length ]
          </artwork>
        </figure>
        <t>
          An address lookup is done on the &lt;target-name&gt;. The
          &lt;ip&gt; is compared to the returned address(es). If any
          address matches, the mechanism matches. 
        </t>
      </section>
      <section title="&quot;mx&quot;" anchor="mech-mx">
        <t>
          This mechanism matches if &lt;ip&gt; is one of the MX hosts
          for a domain name. 
        </t>
        <figure>
          <artwork type="abnf">
MX               = "mx"     [ ":" domain-spec ] [ dual-cidr-length ]
          </artwork>
        </figure>
        <t>
          check_host() first performs an MX lookup on the
          &lt;target-name&gt;. Then it performs an address lookup on
          each MX name returned. The &lt;ip&gt; is compared to each
          returned IP address. To prevent DoS attacks, a limit of 10
          MX names MUST be enforced (see <xref target="security" />).
          If any address matches, the mechanism matches.
        </t>
        <t>
          Note regarding implicit MXes: If the &lt;target-name&gt; has
          no MX records, check_host() MUST NOT pretend the target is its single
          MX, and MUST NOT default to an A lookup on the
          &lt;target-name&gt; directly. This behavior breaks with the
          legacy "implicit MX" rule. See <xref target="RFC2821"/> Section 5. If
          such behavior is desired, the publisher should specify an "a"
          directive. 
        </t>
      </section>
      <section title="&quot;ptr&quot;" anchor="mech-ptr">
        <t>
          This mechanism tests if the DNS reverse mapping for
          &lt;ip&gt; exists and correctly points to a domain name
          within a particular domain.
        </t>
        <figure>
          <artwork type="abnf">
PTR              = "ptr"    [ ":" domain-spec ]
          </artwork>
        </figure>
        <t>
          First the &lt;ip&gt;'s name is looked up using this
          procedure: perform a DNS reverse-mapping for &lt;ip&gt;,
          looking up the corresponding PTR record in "in-addr.arpa."
          if the address is an IPv4 one and in "ip6.arpa." if it is an
          IPv6 address.  For each record returned, validate the domain
          name by looking up its IP address.  To prevent DoS attacks,
          a limit of 10 PTR names MUST be enforced (see <xref
          target="security" />).  If &lt;ip&gt; is among the returned
          IP addresses, then that domain name is validated. In
          pseudocode:
        </t>
        <figure>
          <artwork>
sending-domain_names := ptr_lookup(sending-host_IP);
if more than 10 sending-domain_names are found, use at most 10.
for each name in (sending-domain_names) {
  IP_addresses := a_lookup(name);
  if the sending-domain_IP is one of the IP_addresses {
    validated-sending-domain_names += name;
  }
}
          </artwork>
        </figure>
        <t>
          Check all validated domain names to see if they end in the
          &lt;target-name&gt; domain. If any do, this mechanism
          matches.  If no validated domain name can be found, or if none
          of the validated domain names end in the &lt;target-name&gt;,
          this mechanism fails to match. If a DNS error occurs while
          doing the PTR RR lookup, then this mechanism fails to match.
          If a DNS error occurs while doing an A RR lookup, then that
          domain name is skipped and the search continues.
        </t>
        <figure>
          <preamble>Pseudocode:</preamble>
          <artwork>
for each name in (validated-sending-domain_names) {
  if name ends in &lt;domain-spec&gt;, return match.
  if name is &lt;domain-spec&gt;, return match.
}
return no-match.
          </artwork>
        </figure>
        <t>
          This mechanism matches if the &lt;target-name&gt; is either an
          ancestor of a validated domain name, or if the
          &lt;target-name&gt; and a validated domain name are the same.
          For example: "mail.example.com" is within the domain "example.com",
          but "mail.bad-example.com" is not.
        </t>
        <t>
          Note: Use of this mechanism is discouraged because it is
          slow, is not as reliable as other mechanisms in cases of DNS
          errors and it places a large burden on the arpa name
          servers. If used, proper PTR records must be in place for
          the domain's hosts and the "ptr" mechanism should be one of
          the last mechanisms checked.
        </t>
      </section>
      <section title="&quot;ip4&quot; and &quot;ip6&quot;" anchor="mech-ip">
        <t>
          These mechanisms test if &lt;ip&gt; is contained within a
          given IP network. 
        </t>
        <figure>
          <artwork type="abnf">
IP4              = "ip4"      ":" ip4-network   [ ip4-cidr-length ]
IP6              = "ip6"      ":" ip6-network   [ ip6-cidr-length ]

ip4-cidr-length  = "/" 1*DIGIT
ip6-cidr-length  = "/" 1*DIGIT
dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ]

ip4-network      = ; as per conventional dotted quad notation,
          ; e.g. 192.0.2.0
ip6-network      = ; as per [RFC 3513], section 2.2,
          ; e.g. 2001:DB8::CD30
          </artwork>
        </figure>
        <t>
          The &lt;ip&gt; is compared to the given network. If
          CIDR-length high-order bits match, the mechanism matches. 
        </t>
        <t>
          If ip4-cidr-length is omitted it is taken to be "/32". If
          ip6-cidr-length is omitted it is taken to be "/128".  It is
          not permitted to omit parts of the IP address instead of
          using CIDR notations.  That is, use 10.23.45.0/24 instead of
          10.23.45.
        </t>
      </section>
      <section title="&quot;exists&quot;" anchor="mech-exists">
        <t>
          This mechanism is used to construct an arbitrary domain name
          that is used for a DNS A record query. It allows for
          complicated schemes involving arbitrary parts of the mail
          envelope to determine what is permitted.
        </t>
        <figure>
          <artwork type="abnf">
exists           = "exists"   ":" domain-spec
          </artwork>
        </figure>
        <t>
          The domain-spec is expanded as per <xref
          target="macros"/>. The resulting domain name is used for a
          DNS A RR lookup. If any A record is returned, this mechanism
          matches. The lookup type is 'A' even when the connection
          type is IPv6.
        </t>
        <t>
          Domains can use this mechanism to specify arbitrarily complex
          queries. For example, suppose example.com publishes the record: 
        </t>
        <t>
          <list style="empty">
            <t> v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all </t>
          </list>
        </t>
        <t>
          The &lt;target-name&gt; might expand to
          "1.2.0.192.someuser._spf.example.com". This makes fine-grained
          decisions possible at the level of the user and client IP address. 
        </t>
        <t>
          This mechanism enables queries that mimic the style of tests that
          existing DNSBL lists use. 
        </t>
      </section>
    </section>
    <section title="Modifier Definitions" anchor="modifiers">
      <t>
        Modifiers are name/value pairs that provide additional
        information. Modifiers always have an "=" separating the
        name and the value.
      </t>
      <t>
        The modifiers defined in this document ("redirect" and
        "exp") MAY appear anywhere in the record, but SHOULD
        appear at the end, after all mechanisms.  Ordering of
        these two modifiers does not matter.  These modifiers MUST NOT
        appear in a record more than once each.  If they do, then
        check_host() exits with a result of "PermError".
      </t>
      <t>
        Unrecognized modifiers SHOULD be ignored no matter where in
        a record, nor how often.  This allows implementations of
        this document to handle records with modifiers that are
        defined in other specifications.
      </t>
      <section title="redirect: Redirected Query" anchor="mod-redirect">
        <t>
          If all mechanisms fail to match, and a "redirect" modifier is
          present, then processing proceeds as follows.
        </t>
        <figure>
          <artwork type="abnf">
redirect         = "redirect" "=" domain-spec
          </artwork>
        </figure>
        <t>
          The domain-spec portion of the redirect section is expanded as per
          the macro rules in <xref target="macros"/>. Then check_host() is
          evaluated with the resulting string as the &lt;domain&gt;. The
          &lt;ip&gt; and &lt;sender&gt;
          arguments remain the same as current evaluation of check_host(). 
        </t>
        <t>
          The result of this new evaluation of check_host() is then considered
          the result of the current evaluation. 
        </t>
        <t>
          Note that the newly queried domain may itself specify redirect
          processing. 
        </t>
        <t>
          This facility is intended for use by organizations that wish to
          apply the same record to multiple domains. For example: 
        </t>
        <figure>
          <artwork>
  la.example.com. TXT "v=spf1 redirect=_spf.example.com"
  ny.example.com. TXT "v=spf1 redirect=_spf.example.com"
  sf.example.com. TXT "v=spf1 redirect=_spf.example.com"
_spf.example.com. TXT "v=spf1 mx:example.com -all"
          </artwork>
        </figure>
        <t>
          In this example, mail from any of the three domains is described by
          the same record. This can be an administrative advantage. 
        </t>
        <t>
          Note: In general, the domain "A" cannot reliably use a
          redirect to another domain "B" not under the same
          administrative control. Since the &lt;sender&gt; stays the
          same, there is no guarantee that the record at domain "B"
          will correctly work for addresses in domain "A", especially
          if domain "B" uses mechanisms involving localparts. An
          "include" directive may be more appropriate.
        </t>
        <t>
          For clarity it is RECOMMENDED that any "redirect" modifier appear as
          the very last term in a record. 
        </t>
      </section>
      <section title="exp: Explanation" anchor="mod-exp">
        <figure>
          <artwork type="abnf">
explanation      = "exp" "=" domain-spec
          </artwork>
        </figure>
        <t>
          If check_host() results in a "Fail" due to a mechanism match
          (such as "-all"), and the "exp" modifier is present, then
          the explanation string returned is computed as described
          below. If no "exp" modifier is present, then either a
          default explanation string or an empty explanation string
          may be returned.
        </t>
        <t>
          The &lt;domain-spec&gt; is macro expanded (see <xref
          target="macros"/>) and becomes the &lt;target-name&gt;. The
          DNS TXT record for the &lt;target-name&gt; is fetched.
        </t>
        <t>
          If &lt;domain-spec&gt; is empty, or there are any processing
          errors (any RCODE other than 0), or if no records are
          returned, or if more than one record is returned, then
          proceed as if no exp modifier was given.
        </t>
        <t>
          The fetched TXT record's strings are concatenated with no
          spaces, and then treated as an &lt;explain-string&gt;
          which is macro-expanded. This final result is the
          explanation string.
        </t>
        <t>
          Software evaluating check_host() can use this string to
          communicate information from the publishing domain in the
          form of a short message or URL.  Software should make it
          clear that the explanation string comes from a third
          party. For example, it can prepend the macro string "%{o}
          explains: " to the explanation.
        </t>
        <t>
          Implementations MAY limit the length of the resulting
          explanation string to allow for other protocol constraints
          and/or reasonable processing limits.  The SPF client SHOULD
          make it clear when an explanation string is coming from a
          third party, such as shown in <xref target="op-result-fail" />.
        </t>
        <t> Suppose example.com has this record </t>
        <t>
          <list style="empty">
            <t> v=spf1 mx -all exp=explain._spf.%{d}</t>
          </list>
        </t>
        <t>
          Here are some examples of possible explanation TXT records at
          explain._spf.example.com: 
        </t>
        <t>
          <list style="empty">
            <t> Example.com mail should only be sent by its own servers. <list style="empty">
                <t>
                  <list style="hanging">
                    <t hangText="--">a simple, constant message</t>
                  </list>
                </t>
              </list>
            </t>
          </list>
        </t>
        <t>
          <list style="empty">
            <t> %{i} is not one of %{d}'s designated mail servers. <list style="empty">
                <t>
                  <list style="hanging">
                    <t hangText="--">a message with a little more info,
                      including the IP address that failed the check
                    </t>
                  </list>
                </t>
              </list>
            </t>
          </list>
        </t>
        <t>
          <list style="empty">
            <t> See http://%{d}/why.html?s=%{S}&amp;i=%{I} <list style="empty">
                <t>
                  <list style="hanging">
                    <t hangText="--">a complicated example that
                    constructs a URL with the arguments to check_host()
                    so that a web page can be generated with detailed,
                    custom instructions
                    </t>
                  </list>
                </t>
              </list>
            </t>
          </list>
        </t>
        <t>
          Note: During recursion into an "include" mechanism, exp=
          modifiers do not propagate out.  In contrast, during
          execution of a "redirect" modifier, the explanation string
          from the target of the redirect is used.
        </t>
      </section>
    </section>
    <section title="Miscellaneous" anchor="misc">
      <section title="Processing Limits" anchor="limits">
        <t>
          During processing, an evaluation of check_host() may require
          additional evaluations of check_host() due to the "include"
          mechanism and/or the "redirect" modifier.
        </t>
        <t>
          In order to prevent Denial-of-Service (DoS) attacks, the
          total number of DNS lookups must be limited.  The subject of
          a DoS attack can be either the SPF client directly, the
          domain owner of the claimed sender, or some third party
          domain that is referenced in the SPF record.
        </t>
        <t>
          Of these, the case of a third party referenced in the SPF
          record is the easiest for a DoS attack to effectively
          exploit.  For example, a malicious person could create an
          SPF record with many references to a victim domain, send
          many e-mails to different SPF clients and the SPF clients
          would create a DoS attack.  In effect, the SPF clients are
          being used to amplify the attacker's bandwidth by using
          fewer bytes in the SMTP session than is generated by the DNS
          queries.  Using SPF clients also allows the attacker to hide
          the true source of the attack.
        </t>
        <t>
          As a result, limits that may seem reasonable for an
          individual mail server can still allow an unreasonable
          amount of bandwidth amplification.  Therefore the processing
          limits need to be quite small.
        </t>
        <t>
          SPF implementations MUST limit the number of mechanism that
          do DNS lookups to at most 10, if this number is exceeded, a
          PermError MUST be returned.  The mechanisms that count
          against this limit are "include", "a", "mx", "ptr", "exists"
          and the "redirect" modifier.  The "all", "ip4" and "ip6"
          mechanisms do not require DNS lookups and therefore do not
          count against this limit.  The "exp" modifier requires a DNS
          lookup, but it is not counted as it is used only in the case
          of errors.
        </t>
        <t>
          When evaluating the "mx" and "ptr" mechanisms, or the %{p}
          macro, there MUST be a limit of no more than 10 MX or PTR
          RRs looked up and checked.
        </t>
        <t>
          SPF implementation SHOULD limit the total amount of data
          obtained from the DNS queries.  For example, when DNS over
          TCP or EDNS0 are available, there may need to be an explicit
          limit to how much data will be accepted to prevent excessive
          bandwidth usage or memory usage, and DoS attacks.
        </t>
        <t>
          Implementations must be prepared to handle records that are
          set up incorrectly or maliciously. 
        </t>
        <t>
          MTAs or other processors MAY also impose a limit on the
          maximum amount of elapsed time to evaluate
          check_host(). Such a limit SHOULD allow at least 20
          seconds. If such a limit is exceeded, the result of
          authentication SHOULD be "TempError".
        </t>
        <t>
          Domains publishing records SHOULD try to keep the number of
          "include" mechanisms and chained "redirect" modifiers to a
          minimum. Domains SHOULD also try to minimize the amount of
          other DNS information needed to evaluate a record. This can
          be done by choosing directives that require less DNS
          information and placing lower cost mechanisms earlier in the
          SPF record.
        </t>
        <t> For example, consider a domain set up as: </t>
        <figure>
          <artwork>
example.com.      IN MX   10 mx.example.com.
mx.example.com.   IN A    192.0.2.1
a.example.com.    IN TXT  "v=spf1 mx:example.com -all"
b.example.com.    IN TXT  "v=spf1 a:mx.example.com -all"
c.example.com.    IN TXT  "v=spf1 ip4:192.0.2.1 -all"
          </artwork>
        </figure>
        <t>
          Evaluating check_host() for the domain "a.example.com"
          requires the MX records for "example.com", and then the A
          records for the listed hosts.  Evaluating for
          "b.example.com" only requires the A records.  Evaluating for
          "c.example.com" requires none.
        </t>
        <t>
          However, there may be administrative considerations: Using
          "a" over "ip4" allows hosts to be renumbered easily. Using
          "mx" over "a" allows the set of mail hosts to be changed
          easily.
        </t>
      </section>
      <section title="The Received-SPF header">
        <t>
          It is RECOMMENDED that SMTP receivers record the result of
          SPF processing in the message headers.  If an SMTP receiver
          chooses to do so, it SHOULD use the "Received-SPF" header
          defined here.  This information is intended for the
          recipient.  (Information intended for the sender described
          in <xref target="mod-exp"/>, Explanation.)
        </t>
        <t>
          The Received-SPF header is a trace field (See <xref
          target="RFC2822"/> section 3.6.7) and SHOULD be
          prepended to existing headers, above the Received: header
          that is generated by the SMTP receiver.  It MUST appear
          above any other Received-SPF headers in the message.  The
          header has the format:
        </t>
        <t>   
          <figure>
            <artwork type="abnf">
header           = "Received-SPF:" [CFWS] result [CFWS]
                   [ key-value-list ]

result           = "Pass" / "Fail" / "TempError" / "SoftFail" /
                   "Neutral" / "None" / "PermError"

key-value-list   = key-value-pair *( ";" [CFWS] key-value-pair )
                   [";"]

key-value-pair   = name [CFWS] "=" ( dot-atom / quoted-string )

dot-atom         = ; unquoted word as per [RFC2822]

quoted-string    = ; quoted string as per [RFC2822]

CFWS             = ; comment or folding white space as per [RFC2822]
            </artwork>
          </figure>
        </t>
        <t>
          The &lt;comment-string&gt; should convey supporting
          information for the result, such as &lt;ip&gt;,
          &lt;sender&gt; and &lt;domain&gt;.
        </t>
        <t>
          SPF clients may append zero or more of the following key-value-pairs
          at their discretion:
        </t>
        <t>
          <list style="hanging" hangIndent="15">
            <t hangText="receiver">       the host name of the SPF client</t>
            <t hangText="client-ip">      the IP address of the SMTP client</t>
            <t hangText="envelope-from">  the envelope sender address</t>
            <t hangText="helo">           the host name given in the HELO
              or EHLO command
            </t>
            <t hangText="mechanism">      the mechanism that matched (if
              no mechanisms matched, substitute the word "default".)
            </t>
            <t hangText="problem">        if an error was returned,
              details about the error
            </t>
          </list>
        </t>
        <t>
          Other key-value pairs may be defined by SPF clients.  Until a new key
          name becomes widely accepted, new key names should start with "x-".
        </t>
        <t>
          SPF clients MUST make sure that the Received-SPF header does
          not contain invalid characters, is excessively long, or
          contain malicious data that has been provided by the sender.
        </t>
        <t>
          Examples of various header styles that could be generated:
          <figure>
            <artwork>
Received-SPF: Pass (mybox.example.org: domain of
   myname@example.com designates 192.0.2.1 as permitted sender)
      receiver=mybox.example.org; client-ip=192.0.2.1;
      envelope-from=&lt;myname@example.com&gt;; helo=foo.example.com;
            </artwork>
          </figure>
          <figure>
            <artwork>
Received-SPF: Fail (mybox.example.org: domain of
                    myname@example.com does not designate
                    192.0.2.1 as permitted sender)
                    receiver=mybox.example.org;
                    client-ip=192.0.2.1;
                    envelope-from=&lt;myname@example.com&gt;;
                    helo=foo.example.com;
            </artwork>
          </figure>
          <figure>
            <artwork>     
Received-SPF: SoftFail (mybox.example.org: domain of
                        transitioning myname@example.com discourages
                        use of 192.0.2.1 as permitted sender)
            </artwork>
          </figure>
          <figure>
            <artwork>     
Received-SPF: Neutral (mybox.example.org: 192.0.2.1 is neither
                       permitted nor denied by domain of
                       myname@example.com)
            </artwork>
          </figure>
          <figure>
            <artwork>     
Received-SPF: None (mybox.example.org: myname@example.com does
                    not designate permitted sender hosts)
            </artwork>
          </figure>
          <figure>
            <artwork>     
Received-SPF: PermError (mybox.example.org: domain
                         of myname@example.com used an invalid
                         SPF mechanism)
            </artwork>
          </figure>
          <figure>
            <artwork>     
Received-SPF: TempError (mybox.example.org: error in processing
                     during lookup of myname@example.com: DNS
                     timeout)
            </artwork>
          </figure>
        </t>
      </section>
    </section>
    <section title="Macros" anchor="macros">
      <section title="Macro definitions">
        <t>
          Many mechanisms and modifiers perform macro interpolation on
          part of the term.
        </t>
        <figure>
          <artwork type="abnf">
domain-spec      = macro-string domain-end
domain-end       = ( "." toplabel ) / macro-expand
toplabel         = ALPHA / ALPHA *[ alphanum / "-" ] alphanum
                   ; LDH rule (See [RFC3696])
alphanum         = ALPHA / DIGIT
macro-string     = *( macro-expand / macro-literal )
explain-string   = *( macro-string / SP )
macro-expand     = ( "%{" macro-letter transformer *delimiter "}" )
                   / "%%" / "%_" / "%-"
macro-literal    = %x21-24 / %x26-7E
                   ; visible characters except "%"
macro-letter     = "s" / "l" / "o" / "d" / "i" / "p" / "h" /
                   "c" / "r" / "t"
transformer      = *DIGIT [ "r" ]
delimiter        = "." / "-" / "+" / "," / "/" / "_" / "="
          </artwork>
        </figure>
        <t>A literal "%" is expressed by "%%". <list style="empty">
            <t>"%_" expands to a single " " space.</t>
            <t>"%-" expands to a URL-encoded space, viz. "%20".</t>
          </list>
        </t>
        <t> The following macro letters are expanded in term arguments: </t>
        <t>
          <list style="empty">
            <t>
              <list style="hanging" hangIndent="2">
                <t hangText="s">= &lt;sender&gt;</t>
                <t hangText="l">= local-part of &lt;sender&gt;</t>
                <t hangText="o">= domain of &lt;sender&gt;</t>
                <t hangText="d">= &lt;domain&gt;</t>
                <t hangText="i">= &lt;ip&gt;</t>
                <t hangText="p">= the validated domain name of &lt;ip&gt;</t>
                <t hangText="v">= the string "in-addr" if &lt;ip&gt;
                  is ipv4, or "ip6" if &lt;ip&gt; is ipv6
                  </t>
                <t hangText="h">= HELO/EHLO domain</t>
              </list>
            </t>
          </list>
        </t>
        <t> The following macro letters are only allowed in "exp" text: </t>
        <t>
          <list style="empty">
            <t>
              <list style="hanging" hangIndent="2">
                <t hangText="c">= SMTP client IP (easily readable format)</t>
                <t hangText="r">= domain name of host performing the check</t>
                <t hangText="t">= current timestamp
                </t>
              </list>
            </t>
          </list>
        </t>
        <t>
          A '%' character not followed by a '{', '%', '-', or '_'
          character is a syntax error. So, 
          <list style="empty">
            <t>-exists:%(ir).sbl.spamhaus.org</t>
          </list>
          is incorrect and will cause check_host() to return a
          "PermError". Instead, say 
          <list style="empty">
            <t>-exists:%{ir}.sbl.spamhaus.org</t>
          </list>
        </t>
        <t> Optional transformers are:
          <list style="empty">
            <t>
              <list style="hanging" hangIndent="7">
                <t hangText="*DIGIT">: zero or more digits</t>
                <t hangText="'r'">: reverse value, splitting on dots
                  by default
                </t>
              </list>
            </t>
          </list>
        </t>
        <t>
          If transformers or delimiters are provided, the replacement
          value for a macro letter is split into parts. After
          performing any reversal operation and/or removal of
          left-hand parts, the parts are rejoined using "." and not
          the original splitting characters.
        </t>
        <t>
          By default, strings are split on "." (dots). Note that no
          special treatment is given to leading, trailing or
          consecutive delimiters, and so the list of parts may contain
          empty strings. Macros may specify delimiter characters which
          are used instead of ".".
        </t>
        <t>
          The 'r' transformer indicates a reversal operation: if the
          client IP address were 192.0.2.1, the macro %{i} would
          expand to "192.0.2.1" and the macro %{ir} would expand to
          "1.2.0.192".
        </t>
        <t>
          The DIGIT transformer indicates the number of right-hand
          parts to use, after optional reversal. If a DIGIT is
          specified, the value MUST be nonzero. If no DIGITs are
          specified, or if the value specifies more parts than are
          available, all the available parts are used. If the DIGIT
          was 5, and only 3 parts were available, the macro
          interpreter would pretend the DIGIT was 3. Implementations
          MUST support at least a value of 128, as that is the maximum
          number of labels in a domain name.
        </t>
        <t>
          The "s" macro expands to the &lt;sender&gt; argument. It is
          an e-mail address with a localpart, an "@" character, and a
          domain. The "l" macro expands to just the localpart. The "o"
          macro expands to just the domain part. Note that these
          values remain the same during recursive and chained
          evaluations due to "include" and/or "redirect".  Note also
          that if the original &lt;sender&gt; had no localpart, the
          localpart was set to "postmaster" in initial processing (see
          <xref target="initial"/>).
        </t>
        <t>
          For IPv4 addresses, both the "i" and "c" macros expand to the
          standard dotted-quad format. 
        </t>
        <t>
          For IPv6 addresses, the "i" macro expands to a dot-format
          address; it is intended for use in %{ir}. The "c" macro may
          expand to any of the hexadecimal colon-format addresses
          specified in <xref target="RFC3513"/> section 2.2. It is
          intended for humans to read.
        </t>
        <t>
          The "p" macro expands to the validated domain name of
          &lt;ip&gt;. The procedure for finding the validated domain
          name is defined in <xref target="mech-ptr"/>.  If the
          &lt;domain&gt; is present in the list of validated domains,
          it SHOULD be used.  Otherwise, if a subdomain of the
          &lt;domain&gt; is present, it SHOULD be used.  Otherwise,
          any name from the list may be used.  If there are no
          validated domain name or if a DNS error occurs, the string
          "unknown" is used.
        </t>
        <t>
          The "r" macro expands to the name of the receiving MTA. This
          SHOULD be a fully qualified domain name, but if one does not
          exist (as when the checking is done by a script) or if
          policy restrictions dictate otherwise, the word "unknown"
          should be substituted. The domain name may be different than
          the name found in the MX record that the client MTA used to
          locate the receiving MTA.
        </t>
        <t>
          The "t" macro expands to the decimal representation of the
          approximate number of seconds since the Epoch (Midnight,
          January 1st, 1970, UTC).  This is the same value as returned
          by the POSIX time() function in most standards compliant
          libraries.
        </t>
        <t>
          When the result of macro expansion is used in a domain name
          query, if the expanded domain name exceeds 253 characters
          (the maximum length of a domain name), the left side is
          truncated to fit, by removing successive subdomains until
          the total length does not exceed 253 characters.
        </t>
        <t>
          Uppercased macros expand exactly as their lower case
          equivalents, and are then URL escaped. URL escaping for the
          non-uric characters is described in <xref target="RFC2396"/>.
        </t>
        <t>
          Note: Domains should avoid using the "s", "l", "o" or "h"
          macros in conjunction with any mechanism directive. While
          these macros are powerful and allow per-user records to be
          published, they severely limit the ability of
          implementations to cache results of check_host() and they
          reduce the effectiveness of DNS caches.
        </t>
        <t>
          Implementations should be aware that if no directive
          processed during the evaluation of check_host() contains an
          "s", "l", "o" or "h" macro, then the results of the
          evaluation can be cached on the basis of &lt;domain&gt; and
          &lt;ip&gt; alone for as long as the shortest TTL of all the
          DNS records involved.
        </t>
      </section>
      <section title="Expansion Examples">
        <t>
          <list>
            <t>The &lt;sender&gt; is strong-bad@email.example.com.</t>
            <t>The IPv4 SMTP client IP is 192.0.2.3.</t>
            <t>The IPv6 SMTP client IP is 5f05:2000:80ad:5800::1.</t>
            <t>The PTR domain name of the client IP is mx.example.org.</t>
          </list>
        </t>
        <figure>
          <artwork>
macro                       expansion
-------  ----------------------------
%{s}     strong-bad@email.example.com
%{o}                email.example.com
%{d}                email.example.com
%{d4}               email.example.com
%{d3}               email.example.com
%{d2}                     example.com
%{d1}                             com
%{dr}               com.example.email
%{d2r}                  example.email
%{l}                       strong-bad
%{l-}                      strong.bad
%{lr}                      strong-bad
%{lr-}                     bad.strong
%{l1r-}                        strong
          </artwork>
        </figure>
        <figure>
          <artwork>
macro-string                                               expansion
--------------------------------------------------------------------
%{ir}.%{v}._spf.%{d2}             3.2.0.192.in-addr._spf.example.com
%{lr-}.lp._spf.%{d2}                  bad.strong.lp._spf.example.com

%{lr-}.lp.%{ir}.%{v}._spf.%{d2}
bad.strong.lp.3.2.0.192.in-addr._spf.example.com

%{ir}.%{v}.%{l1r-}.lp._spf.%{d2}
3.2.0.192.in-addr.strong.lp._spf.example.com

%{d2}.trusted-domains.example.net
example.com.trusted-domains.example.net

IPv6:
%{ir}.%{v}._spf.%{d2}         1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.
5.d.a.0.8.0.0.0.2.5.0.f.5.ip6._spf.example.com
          </artwork>
        </figure>
      </section>
    </section>
    <section title="Implications">
      <t>
        This section outlines the major implications that adoption of this
        document will have on various entities involved in Internet e-mail.
        It is intended to make clear to the reader where this document
        knowingly affects the operation of such entities.  This section is
        not a "how-to" manual, nor a "best practices" document, and is not a
        comprehensive list of what such entities should do in light of this
        document.
      </t>
      <t>
        This section is non-normative.
      </t>
      <section title="Sending Domains">
        <t>
          Domains that wish to be compliant with this specification
          will need to determine the list of hosts that they allow to
          use their domain name in the "HELO" and "MAIL FROM"
          identities.  It is recognized that forming such a list is
          not just a simple technical exercise, but involves policy
          decisions with both technical and administrative
          considerations.
        </t>
        <t>
          It can be helpful to publish records that include a
          "tracking exists:" mechanism.  By looking at the name server
          logs, an incompletely list may be generated. For example:
          <list>
            <t>v=spf1 exists:_h.%{h}._l.%{l}._o.%{o}._i.%{i}._spf.%{d} ?all</t>
          </list>
        </t>
              

      </section>
      <section title="Mailing Lists">
        <t>
          Mailing lists must be aware of how they re-inject mail that
          is sent to the list. Mailing lists MUST comply with the
          requirement in <xref target="RFC2821"/> Section 3.10 and
          <xref target="RFC1123"/> Section 5.3.6 that say that the
          reverse-path MUST be changed to be the address of a person
          or other entity who administers the list.  While the reasons
          for changing the reverse-path are many and long standing,
          SPF adds enforcement to this requirement.
        </t>
        <t>
          In practice, almost all mailing list software in use already
          complies with this requirement.  Mailing lists that do not
          comply, may or may not encounter problems depending on how
          access to the list is restricted.  Such lists that are
          entirely internal to a domain (only people in the domain can
          send to or receive from the list) are not affected.
        </t>
      </section>
      <section title="Forwarding Services and Aliases">
        <t>
          Forwarding services take mail that is received at a mailbox
          and direct it to some external mailbox.  At the time of this
          writing, the near-universal practice of such services is to
          use the original MAIL FROM of a message when re-injecting
          it for delivery to the external mailbox.  <xref
          target="RFC1123"/> and <xref target="RFC2821"/> describe this
          action as an "alias" rather than a "mail list".  This means
          the external mailbox's MTA sees all such mail in a
          connection from a host of the forwarding service, and so the
          "MAIL FROM" identity will not in general pass authorization.
        </t>
        <t>
          There are several possible ways that this authorization
          failure can be ameliorated.  If the owner of the external
          mailbox wishes to trust the forwarding service, they can
          direct the external mailbox's MTA to skip such tests when
          the client host belongs to the forwarding service.  Tests
          against some other identity may also be used to override the
          test against the "MAIL FROM" identity.
        </t>
        <t>
          For larger domains, it may not be possible to have a
          complete or accurate list of forwarding services used by the
          owners of the domain's mailboxes.  In such cases, white
          lists of generally recognized forwarding services could be
          employed.
        </t>
        <t>
          Forwarding services can also solve the problem by using
          MAIL FROM that contain their own domain.  This means
          that mail bounced from the external mailbox will have to be
          re-bounced by the forwarding service.  Various schemes to do
          this exist though they vary widely in complexity and
          resource requirements on the part of the forwarding service.
          Several popular MTAs can change "alias" semantics to
          "mailing list" semantics by including an adding another
          alias with "owner-" added to the beginning of the alias
          name.  (e.g. an alias of "friends: george@example.com,
          fred@example.org" would need another alias of the form
          "owner-friends: localowner")
        </t>
      </section>
      <section title="Mail Services">
        <t>
          Entities that offer mail services to other domains such as
          sending of bulk mail will may have to alter their mail in
          light of the authorization check in this document.  If the
          MAIL FROM used for such e-mail uses the domain of the
          mail service provider, then the provider needs only to
          ensure that their sending host is authorized by their own
          SPF record, if any.
        </t>
        <t>
          If the MAIL FROM does not use the mail service provider's
          domain, then extra care must be taken.  The SPF record
          format has several options for authorizing the sending MTAs
          of another domain (the service provider's)
        </t>
      </section>
      <section title="MTA Relays">
        <t>
          The authorization check generally precludes the use of arbitrary MTA
          relays between sender and receiver of an e-mail message.
        </t>
        <t>
          Within an organization, MTA relays can be effectively deployed.
          However, for purposes of this document, such relays are effectively
          invisible.  The "MAIL FROM" identity authorization check is a check
          between border MTAs.
        </t>
        <t>
          For mail senders, this means that published SPF records must
          authorize any MTAs that actually send across the Internet.  Usually,
          these are just the border MTAs as internal MTAs simply forward mail
          to these MTAs for delivery.
        </t>
        <t>
          Mail receivers will generally want to perform the authorization check
          at the border MTAs.  This allows mail that fails to be rejected
          during the SMTP session rather than bounced.  Internal MTAs then do
          not perform the authorization test.  To perform the authorization
          test other than at the border, the host that first transferred the
          message to the organization must be determined, which can be
          difficult to extract from headers.  Testing other than at the border
          is not recommended.
        </t>
      </section>
    </section>
    <section title="Security Considerations" anchor="security">
      <t>
        The "MAIL FROM" and "HELO" identity authorizations must not be
        construed to provide more assurance than it does.  It is
        entirely possible for a malicious sender to inject a message
        using their own domain in the identities used by SPF, to have
        that domain's SPF record authorize the sending host, and yet
        the message content can easily claim other identities in the
        headers.  Unless the user, or the MUA takes care to note that
        the authorized identity does not match the other, more
        commonly presented identities (such as the From: header), the
        user may be lulled into a false sense of security.
      </t>
      <t>
        There are two aspects of this protocol that malicious parties could
        exploit to undermine the validity of the check_host() function:
      </t>
      <t>
        <list>
          <t>
            The evaluation of check_host() relies heavily on DNS.  A
            malicious attacker could attack the DNS infrastructure and
            cause check_host() to see spoofed DNS data, and then
            return incorrect results.  This could include returning
            "Pass" for an &lt;ip&gt; value where the actual domain's
            record would evaluate to "Fail".  See <xref
            target="RFC3833"/> for a description of the DNS
            weaknesses.
          </t>
          <t>
            The client IP address, &lt;ip&gt;, is assumed to be
            correct.  A malicious attacker could spoof TCP sequence
            numbers to make mail appear to come from a permitted host
            for a domain that the attacker is impersonating.
          </t>
        </list>
      </t>
      <t>
        As with most aspects of mail, there are a number of ways that
        malicious parties could use the protocol as an avenue of a
        Denial-of-Service (DoS) attack.  The processing limits
        outlined in <xref target="limits"/> are designed to prevent
        attacks such as:
      </t>
      <t>
        <list>
          <t>
            Malicious parties could create SPF records that make many
            references to the target's domain and then send large
            volume mail to other SPF clients that use this SPF record.
            These legitimate machines would then present a DNS load on
            the target as they fetched the relevant DNS references.
          </t>
          <t>
            While implementations of check_host() need to limit the
            number of DNS lookups, malicious domains could publish
            records exceed these limits in an attempt to waste
            computation effort at their targets when they send them
            mail.  Malicious domains could also design SPF records
            that cause excessive memory or CPU usage.
          </t>
          <t>
            Malicious parties could send large volume mail
            purporting to come from the intended target to a wide
            variety of legitimate mail hosts.  These legitimate
            machines would then present a DNS load on the target as
            they fetched the relevant records.
          </t>
        </list>
      </t>
      <t>
        When the authorization check fails, an explanation string may
        be included in the reject response.  Both the sender and the
        rejecting receiver need to be aware that the explanation was
        determined by the publisher of the SPF record checked and, in
        general, not the receiver.  The explanation may contain URLs
        that may be malicious, offensive and/or have misleading text.
        This is probably less of a concern than it may initially seem
        since such messages are returned to the sender, and the
        source is the SPF record published by the domain in the
        identity claimed by that very sender.  To put it another way,
        the only people who see malicious explanation strings are
        people whose messages claim to be from domains that publish
        such strings in their SPF records.
      </t>
      <t>
        SPF uses information supplied by third parties, such as the
        HELO domain name, the MAIL FROM and SPF records.  This
        information is then sent to the receiver in the Received-SPF:
        mail headers and possibly returned to the client MTA in the
        form of an SMTP rejection message.  This information must be
        checked for invalid characters and excessively long lines.
      </t>
    </section>
    <section title="IANA Considerations">
      <t>
        The IANA needs to assign a new Resource Record Type and Qtype
        from the DNS Parameters Registry for the SPF RR type.
      </t>
    </section>
    <section title="Contributors and Acknowledgements">
      <t>
        This document is largely based on the work of Meng Weng Wong
        and Mark Lentczner.  Mark is not listed as an author by his
        request.  While, as this section acknowledges, many people
        have contributed to this document, a very large portion of the
        writing and editing are due to Meng and Mark.
      </t>
      <t>
        This design owes a debt of parentage to <xref target="RMX"/> by
        Hadmut Danisch and to <xref target="DMP"/> by Gordon Fecyk.
        The idea of using a DNS record to check the legitimacy of an
        e-mail address traces its ancestry farther back through
        messages on the namedroppers mailing list by Paul Vixie <xref
        target="Vixie"/> (based on suggestion by Jim Miller) and by
        David Green <xref target="Green"/>.
      </t>
      <t>
        Philip Gladstone contributed macros to the specification,
        multiplying the expressiveness of the language and making
        per-user and per-IP lookups possible.
      </t>
      <t>
        The authors would also like to thank the literally hundreds of
        individuals who have participated in the development of this
        design.  There are far too numerous to name, but they include:
      </t>
      <t>
        <list style="empty">
          <t>The folks on the spf-discuss mailing list.</t>
          <t>The folks on the SPAM-L mailing list.</t>
          <t>The folks on the IRTF ASRG mailing list.</t>
          <t>The folks on the IETF MARID mailing list.</t>
          <t>The folks on #perl.</t>
        </list>
      </t>
    </section>
  </middle>
  <back>
    <references title="Normative References">
      &rfc1035;
      &rfc1123;
      &rfc2034;
      &rfc2119;
      &rfc2181;
      &rfc2234;
      &rfc2396;
      &rfc2821;
      &rfc2822;
      &rfc3513;
    </references>
    <references title="Informative References">
      &rfc1034;
      &rfc1983;
      &rfc2162;
      &rfc3696;
      &rfc3833;
      
      <reference anchor="RMX">
        <front>
          <title>The RMX DNS RR Type for light weight sender authentication</title>
          <author fullname="Hadmut Danish" initials="H." surname="Danish">
            <organization/>
          </author>
          <date year="2003" month="October"/>
        </front>
        <format type="HTML" target="http://www.danisch.de/work/security/antispam.html"/>
        <annotation>Work In Progress</annotation>
      </reference>
      
      <reference anchor="DMP">
        <front>
          <title>Designated Mailers Protocol</title>
          <author fullname="Gordon Fecyk" initials="G." surname="Fecyk">
            <organization/>
          </author>
          <date year="2003" month="December"/>
        </front>
        <format type="HTML" target="http://www.pan-am.ca/dmp/"/>
        <annotation>Work In Progress</annotation>
      </reference>
      
      <reference anchor="Vixie">
        <front>
          <title>Repudiating MAIL FROM</title>
          <author fullname="Paul Vixie" initials="P." surname="Vixie">
            <organization/>
          </author>
          <date year="2002"/>
        </front>
        <format type="HTML" target="http://ops.ietf.org/lists/namedroppers/namedroppers.2002/msg00658.html"/>
      </reference>
      <reference anchor="Green">
        <front>
          <title>Domain-Authorized SMTP Mail</title>
          <author fullname="David Green" initials="D." surname="Green">
            <organization/>
          </author>
          <date year="2002"/>
        </front>
        <format type="HTML" target="http://ops.ietf.org/lists/namedroppers/namedroppers.2002/msg00656.html"/>
      </reference>
    </references>
    <section title="Collected ABNF">
      <t>
        This section is normative and any discrepancies with the ABNF
        fragments in the preceding text are to be resolved in favor of this
        grammar. 
      </t>
      <t>
        See <xref target="RFC2234"/> for ABNF notation. Please note
        that as per this ABNF definition, literal text strings (those
        in quotes) are case-insensitive.  Hence, "mx" matches "mx",
        "MX", "mX" and "Mx".
      </t>
      <figure>
        <artwork type="abnf">
record           = version terms *SP
version          = "v=spf1"

terms            = *( 1*SP ( directive / modifier ) )

directive        = [ prefix ] mechanism
prefix           = "+" / "-" / "?" / "~"
mechanism        = ( all / include
                   / A / MX / PTR / IP4 / IP6 / exists )

all              = "all"
include          = "include"  ":" domain-spec
A                = "a"      [ ":" domain-spec ] [ dual-cidr-length ]
MX               = "mx"     [ ":" domain-spec ] [ dual-cidr-length ]
PTR              = "ptr"    [ ":" domain-spec ]
IP4              = "ip4"      ":" ip4-network   [ ip4-cidr-length ]
IP6              = "ip6"      ":" ip6-network   [ ip6-cidr-length ]
exists           = "exists"   ":" domain-spec

modifier         = redirect / explanation / unknown-modifier
redirect         = "redirect" "=" domain-spec
explanation      = "exp" "=" domain-spec
unknown-modifier = name "=" macro-string

ip4-cidr-length  = "/" 1*DIGIT
ip6-cidr-length  = "/" 1*DIGIT
dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ]

ip4-network      = ; as per conventional dotted quad notation,
          ; e.g. 192.0.2.0
ip6-network      = ; as per [RFC 3513], section 2.2,
          ; e.g. 2001:DB8::CD30

domain-spec      = macro-string domain-end
domain-end       = ( "." toplabel ) / macro-expand
toplabel         = ALPHA / ALPHA *[ alphanum / "-" ] alphanum
                   ; LDH rule (See [RFC3696])
alphanum         = ALPHA / DIGIT
macro-string     = *( macro-expand / macro-literal )
explain-string   = *( macro-string / SP )
macro-expand     = ( "%{" macro-letter transformer *delimiter "}" )
                   / "%%" / "%_" / "%-"
macro-literal    = %x21-24 / %x26-7E
                   ; visible characters except "%"
macro-letter     = "s" / "l" / "o" / "d" / "i" / "p" / "h" /
                   "c" / "r" / "t"
transformer      = *DIGIT [ "r" ]
delimiter        = "." / "-" / "+" / "," / "/" / "_" / "="

name             = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." )

header           = "Received-SPF:" [CFWS] result [CFWS]
                   [ key-value-list ]

result           = "Pass" / "Fail" / "TempError" / "SoftFail" /
                   "Neutral" / "None" / "PermError"

key-value-list   = key-value-pair *( ";" [CFWS] key-value-pair )
                   [";"]

key-value-pair   = name [CFWS] "=" ( dot-atom / quoted-string )

dot-atom         = ; unquoted word as per [RFC2822]

quoted-string    = ; quoted string as per [RFC2822]

CFWS             = ; comment or folding white space as per [RFC2822]
        </artwork>
      </figure>
    </section>
    <section title="Extended Examples" anchor="examples">
      <t> These examples are based on the following DNS setup: </t>
      <figure>
        <artwork>
; A domain with two mail servers, two hosts
; and two servers at the domain name 

$ORIGIN example.com.
@           MX  10 mail-a
MX  20 mail-b
A   192.0.2.10
A   192.0.2.11
amy         A   192.0.2.65
bob         A   192.0.2.66
mail-a      A   192.0.2.129
mail-b      A   192.0.2.130
www         CNAME example.com.

; A related domain

$ORIGIN example.org
@           MX  10 mail-c
mail-c      A   192.0.2.140

; The reverse IP for those addresses

$ORIGIN 2.0.192.in-addr.arpa.
10          PTR example.com.
11          PTR example.com.
65          PTR amy.example.com.
66          PTR bob.example.com.
129         PTR mail-a.example.com.
130         PTR mail-b.example.com.
140         PTR mail-c.example.org.

; A rogue reverse IP domain that claims to be
; something it's not

$ORIGIN 0.0.10.in-addr.arpa.
4           PTR bob.example.com.
        </artwork>
      </figure>
      <section title="Simple Examples">
        <t>
          These examples show various possible published records for
          example.com and which values if &lt;ip&gt; would cause
          check_host() to return "Pass". Note that &lt;domain&gt; is
          "example.com". 
        </t>
        <t> v=spf1 +all <list style="empty">
            <t>-- any &lt;ip&gt; passes</t>
          </list>
        </t>
        <t> v=spf1 a -all <list style="empty">
            <t> -- hosts 192.0.2.10 and 192.0.2.11 pass</t>
          </list>
        </t>
        <t> v=spf1 a:example.org -all <list style="empty">
            <t> -- no sending hosts pass since example.org has no A records</t>
          </list>
        </t>
        <t> v=spf1 mx -all <list style="empty">
            <t> -- sending hosts 192.0.2.129 and 192.0.2.130 pass</t>
          </list>
        </t>
        <t> v=spf1 mx:example.org -all <list style="empty">
            <t> -- sending host 192.0.2.140 passes</t>
          </list>
        </t>
        <t> v=spf1 mx mx:example.org -all <list style="empty">
            <t> -- sending hosts 192.0.2.129, 192.0.2.130, and
              192.0.2.140 pass
            </t>
          </list>
        </t>
        <t> v=spf1 mx/30 mx:example.org/30 -all <list style="empty">
            <t> -- any sending host in 192.0.2.128/30 or
              192.0.2.140/30 passes
            </t>
          </list>
        </t>
        <t> v=spf1 ptr -all <list style="empty">
            <t>-- sending host 192.0.2.65 passes (reverse IP is valid
              and in example.com)
            </t>
            <t>
              -- sending host 192.0.2.140 fails (reverse IP is valid, but not
              in example.com)
            </t>
            <t>-- sending host 10.0.0.4 fails (reverse IP is not valid)</t>
          </list>
        </t>
        <t> v=spf1 ip4:192.0.2.128/28 -all <list style="empty">
            <t>-- sending host 192.0.2.65 fails</t>
            <t>-- sending host 192.0.2.129 passes</t>
          </list>
        </t>
      </section>
      <section title="Multiple Domain Example">
        <t> These examples show the effect of related records: </t>
        <t>
          <list style="empty">
            <t>
              example.org: "v=spf1 include:example.com
              include:example.net -all"
            </t>
          </list>
        </t>
        <t>
          This record would be used if mail from example.org actually came
          through servers at example.com and example.net. Example.org's
          designated servers are the union of example.com and example.net's
          designated servers. 
        </t>
        <t>
          <list style="empty">
            <t>la.example.org: "v=spf1 redirect=example.org"</t>
            <t>ny.example.org: "v=spf1 redirect=example.org"</t>
            <t>sf.example.org: "v=spf1 redirect=example.org"</t>
          </list>
        </t>
        <t>
          These records allow a set of domains that all use the same mail
          system to make use of that mail system's record. In this way, only the
          mail system's record needs to updated when the mail setup changes.
          These domains' records never have to change. 
        </t>
      </section>
      <section title="DNSBL Style Example">
        <t>
          Imagine that, in addition to the domain records listed above, there
          are these: 
        </t>
        <figure>
          <artwork>
$Origin _spf.example.com.
mary.mobile-users                   A 127.0.0.2
fred.mobile-users                   A 127.0.0.2
15.15.168.192.joel.remote-users     A 127.0.0.2
16.15.168.192.joel.remote-users     A 127.0.0.2
          </artwork>
        </figure>
        <t>
          The following records describe users at example.com who mail from
          arbitrary servers, or who mail from personal servers. 
        </t>
        <t>example.com: <figure>
            <artwork>
v=spf1 mx
       include:mobile-users._spf.%{d}
       include:remote-users._spf.%{d}
       -all
            </artwork>
          </figure>
        </t>
        <t>mobile-users._spf.example.com: <figure>
            <artwork>
v=spf1 exists:%{l1r+}.%{d}
            </artwork>
          </figure>
        </t>
        <t>remote-users._spf.example.com: <figure>
            <artwork>
v=spf1 exists:%{ir}.%{l1r+}.%{d}
            </artwork>
          </figure>
        </t>
      </section>
    </section>
  </back>
</rfc>
<!-- vim: set sw=2 ts=2 expandtab: -->
