RFC 5235

Sieve Email Filtering: Spamtest and Virustest Extensions

πŸ“… published January 2008, from ietf

RFC 5235: Sieve Email Filtering: Spamtest and Virustest Extensions ✨

Okay bestie, let's get into RFC 5235 πŸ¦‹. It was written by C. Daboo for the Network Working Group in January 2008, and it's a Standards Track document, so it's a real protocol spec people actually implement πŸ’…. It obsoletes RFC 3685, which means this one is the new and improved version of that earlier spec πŸ‘‘. Its whole job is making spam and virus filtering in Sieve scripts portable across tools 🫢.

Status of This Memo 🌸

This document specifies an Internet standards track protocol for the Internet community, and requests discussion and suggestions for improvements. Please refer to the current edition of the "Internet Official Protocol Standards" (STD 1) for the standardization state and status of this protocol. Distribution of this memo is unlimited.

Abstract πŸ’œ

The Sieve email filtering language "spamtest", "spamtestplus", and "virustest" extensions let users write simple, portable commands for spam and virus tests on email messages ✨. Each extension adds a new test that matches against numeric "scores" πŸ”₯. The actual checks are the job of the underlying Sieve implementation, which has to produce the right input for these tests πŸŽ€.

Table of Contents πŸ“š

   1. Introduction and Overview .......................................2
   2. Conventions Used in This Document ...............................2
   3. Sieve Extensions ................................................3
      3.1. General Considerations .....................................3
      3.2. Test spamtest ..............................................3
           3.2.1. spamtest without :percent Argument ..................4
           3.2.2. spamtest with :percent Argument .....................5
      3.3. Test virustest .............................................7
   4. Security Considerations .........................................9
   5. IANA Considerations .............................................9
      5.1. spamtest Registration ......................................9
      5.2. virustest Registration ....................................10
      5.3. spamtestplus Registration .................................10
   6. References .....................................................10
      6.1. Normative References ......................................10
      6.2. Informative References ....................................11
   Appendix A. Acknowledgments .......................................12
   Appendix B. Important Changes since RFC 3685 ......................12

1. Introduction and Overview 🌈

Okay so, Sieve scripts are everywhere for spam and virus filtering πŸ™ˆ. Sometimes they check things directly inside the script, like a list of "black-listed" senders written right into the code πŸ’€. Other times they test messages that some external spam or virus checker already touched before Sieve got them 🧚. The catch is that every third-party tool has its own way of saying what it found. Usually that's a header added to the message, and the content of that header uses whatever syntax that particular tool invented 😭. So every user ends up writing their own Sieve scripts to match those headers, and the scripts have to stay in sync every time the tool gets updated or swapped out for something else. That means the scripts get tied to one specific environment and lose their portability πŸ’”.

This document is here to fix that, bestie 🫢. It introduces two Sieve tests that work as "generic" tests for spam and viruses in messages processed by Sieve scripts ✨. The spam and virus checks still happen in the underlying Sieve implementation, however that implementation sees fit, so the Sieve spam and virus test commands stay portable πŸ’….

To do numeric comparisons against the returned strings, server implementations MUST also support the Sieve relational [RFC5231] extension, in addition to the extensions described here πŸ”₯. All examples below assume the relational extension is present πŸŽ€.

2. Conventions Used in This Document πŸ¦‹

Conventions for notations are as in [RFC5228] Section 1.1.

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 [RFC2119].

The term "spam" is used in this document to refer to unsolicited or unwanted email messages. This document does not attempt to define what exactly constitutes spam, or how it should be identified, or what actions should be taken when detected πŸ™…β€β™€οΈ.

The term "virus" is used in this document to refer to any type of message whose content can cause malicious damage. This document does not attempt to define what exactly constitutes a virus, or how it should be identified, or what actions should be taken when detected πŸ’€.

3. Sieve Extensions πŸ’–

3.1. General Considerations 🌸

The "spamtest" and "virustest" tests described below evaluate the results of implementation-specific spam and virus checks in a portable way 🫢. The implementation may, for example, check for third-party spam tool headers and work out how those map onto the way the test commands get used 🧚. To make that happen, the underlying Sieve implementation hands each test command a normalized result string as one of its inputs πŸ’…. That normalized result string counts as the value on the left-hand side of the test, and the comparison values in the test command sit on the right-hand side πŸ‘‘.

Here's the vibe for the normalized result. It starts with a digit string, and that number has to fall within the range used by the specific test πŸ”₯. The number tells you how severe the spam or virus situation is, or whether any tests were done at all 😭. After that you might get a single space (%x20) and some arbitrary text, or in one special case, just a single keyword πŸŽ€. The numeric value can be compared against specific values using the Sieve relational [RFC5231] extension together with the "i;ascii-numeric" comparator [RFC4790]. That comparator checks for a numeric value at the start of the string and ignores any extra text after it ✨. The optional text is where implementation-specific details and descriptive comments about the result can live 🌈. You can run standard string comparators against that text if you need to refine behavior, but heads up, that will break the script's portability, because the text will probably be specific to one implementation πŸ™ˆ.

Also, the Sieve relational [RFC5231] ":count" match type can be used to find out whether the underlying implementation actually ran a test πŸ”. If the spam or virus test was done, the ":count" of the normalized result returns the numeric value "1" βœ…. If the test wasn't done, or if the Sieve implementation couldn't figure out whether it was done or not, the ":count" value is "0" (zero) ❌.

3.2. Test spamtest πŸŽ€

           Usage:    spamtest [":percent"] [COMPARATOR] [MATCH-TYPE]
                     <value: string>

Sieve implementations that implement the "spamtest" test use an identifier of either "spamtest" or "spamtestplus" for use with the capability mechanism πŸ’œ.

If the ":percent" argument is not used with any spamtest test, then one or both of "spamtest" or "spamtestplus" capability identifiers MUST be present 🫢.

If the ":percent" argument is used with any spamtest test, then the "spamtestplus" capability identifier MUST be present. Sieve implementations MUST return an error if the ":percent" argument is used and "spamtestplus" is not specified 🚨.

In the interests of brevity and clarity, scripts SHOULD NOT specify both "spamtestplus" and "spamtest" capability identifiers together πŸ™…β€β™€οΈ.

The "spamtest" test evaluates to true if the normalized spamtest result matches the value. The type of match is specified by the optional match argument, which defaults to ":is" if not specified πŸ’….

3.2.1. spamtest without :percent Argument 🌈

When the ":percent" argument is not present in the "spamtest" test, the normalized result string on the left-hand side of the test starts with a numeric value in the range "0" (zero) through "10" πŸ”’. The meanings are summarized in this table:

   +----------+--------------------------------------------------------+
   | spamtest | interpretation                                         |
   | value    |                                                        |
   +----------+--------------------------------------------------------+
   | 0        | message was not tested for spam, or Sieve could not    |
   |          | determine whether any test was done                    |
   |          |                                                        |
   | 1        | message was tested and is clear of spam                |
   |          |                                                        |
   | 2 - 9    | message was tested and may contain spam; a higher      |
   |          | number indicates a greater likelihood of spam          |
   |          |                                                        |
   | 10       | message was tested and definitely contains spam        |
   +----------+--------------------------------------------------------+

The underlying Sieve implementation maps whatever spam check it runs into this numeric range, as appropriate 🧚.

Here's an example to make it click ✨:

           require ["spamtest", "fileinto", "relational", "comparator-
                    i;ascii-numeric"];

           if spamtest :value "eq" :comparator "i;ascii-numeric" "0"
           {
               fileinto "INBOX.unclassified";
           }
           elsif spamtest :value "ge" :comparator "i;ascii-numeric" "3"
           {
               fileinto "INBOX.spam-trap";
           }

In this example, any message that hasn't passed through a spam check tool gets filed into the mailbox "INBOX.unclassified" πŸ“₯. Any message with a normalized result value greater than or equal to "3" gets filed into a mailbox called "INBOX.spam-trap" in the user's mailstore πŸͺ€. Literally so clean πŸ’…πŸ”₯.

Next up: the rest of section 3.2, and then 3.3 on virustest πŸ¦‹πŸ’œ

3.2.2. spamtest with :percent Argument ✨

okay so when the :percent argument is there in the spamtest test, the normalized result string on the left-hand side starts with a number from 0 (zero) through 100 πŸ’… Here's the vibe for each value:

+----------+-------------------------------------------------------+
| spamtest | interpretation                                        |
| value    |                                                       |
+----------+-------------------------------------------------------+
| 0        | message was tested and is clear of spam, or was not   |
|          | tested for spam, or Sieve could not determine whether |
|          | any test was done                                     |
|          |                                                       |
| 1 - 99   | message was tested and may contain spam; a higher     |
|          | percentage indicates a greater likelihood of spam     |
|          |                                                       |
| 100      | message was tested and definitely contains spam       |
+----------+-------------------------------------------------------+

The underlying Sieve implementation maps whatever spam check gets run into that numeric range, as appropriate 🧚

Now, how do you figure out whether the message was even tested for spam? There are two ways to do it πŸ”

a. A test with or without the :percent argument and :count match type, testing for the value 0 as described in Section 3.1.

b. A test without the :percent argument using the :value match type, testing for the normalized result value 0 as described in Section 3.2.1.

Here's an example πŸŽ€

        require ["spamtestplus", "fileinto", "relational",
                 "comparator-i;ascii-numeric"];

        if spamtest :value "eq"
                    :comparator "i;ascii-numeric" "0"
        {
            fileinto "INBOX.unclassified";
        }
        elsif spamtest :percent :value "eq"
                       :comparator "i;ascii-numeric" "0"
        {
            fileinto "INBOX.not-spam";
        }
        elsif spamtest :percent :value "lt"
                       :comparator "i;ascii-numeric" "37"
        {
            fileinto "INBOX.spam-trap";
        }
        else
        {
            discard;
        }

In this example, any message that hasn't gone through a spam check tool gets filed into the mailbox "INBOX.unclassified" 🌸 Any message classified as definitely not containing spam (normalized result value "0") goes into "INBOX.not-spam" πŸ’– Any message with a normalized result value less than "37" lands in a mailbox called "INBOX.spam-trap" in the user's mailstore πŸ•ΈοΈ And anything else gets discarded πŸ’€

Alternatively, the Sieve relational [RFC5231] :count match type can be used πŸ¦‹

        if spamtest :percent :count "eq"
                    :comparator "i;ascii-numeric" "0"
        {
            fileinto "INBOX.unclassified";
        }
        elsif spamtest :percent :value "eq"
                       :comparator "i;ascii-numeric" "0"
        {
            fileinto "INBOX.not-spam";
        }
        elsif spamtest :percent :value "lt"
                       :comparator "i;ascii-numeric" "37"
        {
            fileinto "INBOX.spam-trap";
        }
        else
        {
            discard;
        }

This one gets you exactly the same behavior as the previous one πŸ‘‘


3.3. Test virustest 🦠

         Usage:    virustest [COMPARATOR] [MATCH-TYPE]
                   <value: string>

Sieve implementations that implement the "virustest" test have an identifier of "virustest" for use with the capability mechanism πŸŽ€

The "virustest" test evaluates to true if the normalized result string matches the value. The type of match comes from the optional match argument, which defaults to :is if you don't specify one πŸ’…

The normalized result string on the left side of the test starts with a number from 0 (zero) through 5, and here's what each one means πŸ”

+-----------+-------------------------------------------------------+
| virustest | interpretation                                        |
| value     |                                                       |
+-----------+-------------------------------------------------------+
| 0         | message was not tested for viruses, or Sieve could    |
|           | not determine whether any test was done               |
|           |                                                       |
| 1         | message was tested and contains no known viruses      |
|           |                                                       |
| 2         | message was tested and contained a known virus that   |
|           | was replaced with harmless content                    |
|           |                                                       |
| 3         | message was tested and contained a known virus that   |
|           | was "cured" such that it is now harmless              |
|           |                                                       |
| 4         | message was tested and possibly contains a known      |
|           | virus                                                 |
|           |                                                       |
| 5         | message was tested and definitely contains a known    |
|           | virus                                                 |
+-----------+-------------------------------------------------------+

The underlying Sieve implementation maps whatever virus checks get done into this numeric range, as appropriate. If the message hasn't been categorized by any virus checking tools, then the virustest result is "0" 🧼

Example πŸŽ€

        require ["virustest", "fileinto", "relational", "comparator-
                 i;ascii-numeric"];

        if virustest :value "eq" :comparator "i;ascii-numeric" "0"
        {
            fileinto "INBOX.unclassified";
        }
        if virustest :value "eq" :comparator "i;ascii-numeric" "4"
        {
            fileinto "INBOX.quarantine";
        }
        elsif virustest :value "eq" :comparator "i;ascii-numeric" "5"
        {
            discard;
        }

In this example, any message that hasn't passed through a virus check tool gets filed into the mailbox "INBOX.unclassified" 🌈 Any message with a normalized result value equal to "4" goes into a mailbox called "INBOX.quarantine" in the user's mailstore πŸ”’ Any message with a normalized result value equal to "5" gets discarded (removed) and never reaches the user's mailstore πŸ’€


4. Security Considerations 🚨

Sieve implementations SHOULD ensure that "spamtest" and "virustest" tests only report spam and virus test results for messages that actually went through a legitimate spam or virus check process 😀 Especially if those checks rely on adding and then checking private header fields, the implementation is responsible for making sure the sender or an intermediary can't spoof those headers. Otherwise the implementation could get tricked into returning the wrong result for the test πŸ™ˆ

Server administrators must ensure that the virus checking tools are kept up to date, to provide reasonable protection for users using the "virustest" test. Users should be made aware that the "virustest" test does not provide a 100% reliable way to remove all viruses, and they should keep exercising caution with messages of unknown content and origin. This part is SO important bestie 😭🫢

Beyond that, the "spamtest" and "virustest" extensions don't raise any security considerations that aren't already present in the base [RFC5228] protocol, and those issues are discussed in [RFC5228] πŸ”


5. IANA Considerations πŸŽ€

The following templates specify the IANA registration of the Sieve extensions specified in this document. The registrations for "spamtest" and "virustest" replace the ones from [RFC3685] πŸ’…

5.1. spamtest Registration

   To: iana@iana.org
   Subject: Registration of new Sieve extension

   Capability name: spamtest
   Description:     Provides a test to check for varying likelihood of
                    an email message being spam.
   RFC number:      RFC 5235
   Contact address: The Sieve discussion list <ietf-mta-filters@imc.org>

This information has been added to the list of Sieve extensions given on http://www.iana.org/assignments/sieve-extensions ✨

5.2. virustest Registration

   To: iana@iana.org
   Subject: Registration of new Sieve extension

   Capability name: virustest
   Description:     Provides a test to check for varying likelihood of
                    there being malicious content in an email message.
   RFC number:      RFC 5235
   Contact address: The Sieve discussion list <ietf-mta-filters@imc.org>

This information has been added to the list of Sieve extensions given on http://www.iana.org/assignments/sieve-extensions πŸ¦‹

5.3. spamtestplus Registration

   To: iana@iana.org
   Subject: Registration of new Sieve extension

   Capability name: spamtestplus
   Description:     Provides a test to check for varying likelihood of
                    an email message being spam, possibly using a
                    percentage range.
   RFC number:      RFC 5235
   Contact address: The Sieve discussion list <ietf-mta-filters@imc.org>

This information has been added to the list of Sieve extensions given on http://www.iana.org/assignments/sieve-extensions 🌸


6. References πŸ“š

6.1. Normative References

[RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
           Requirement Levels", BCP 14, RFC 2119, March 1997.

[RFC4790]  Newman, C., Duerst, M., and A. Gulbrandsen, "Internet
           Application Protocol Collation Registry", RFC 4790, March
           2007.

[RFC5228]  Guenther, P., Ed., and T. Showalter, Ed., "Sieve: An Email
           Filtering Language", RFC 5228, January 2008.

[RFC5231]  Segmuller, W. and B. Leiba, "Sieve Email Filtering:
           Relational Extension", RFC 5231, January 2008.

6.2. Informative References

[RFC3685]  Daboo, C., "SIEVE Email Filtering: Spamtest and VirusTest
           Extensions", RFC 3685, February 2004.

Appendix A. Acknowledgments πŸ™

Thanks to Mark E. Mallett, Tony Hansen, Jutta Degener, Ned Freed, Ashish Gawarikar, Alexey Melnikov, Nigel Swinson, and Aaron Stone for comments and corrections πŸ’œ


Appendix B. Important Changes since RFC 3685 πŸ”₯

Listed below are some of the major changes from the previous specification [RFC3685], which this one supersedes πŸ‘€

  1. A ":percent" argument has been added to the "spamtest" test, adding a new 0-100 numerical range for test results.
  2. A "spamtestplus" requires item has been added to indicate the presence of this extension in scripts.
  3. The "count" match type from [RFC5231] can now be used to determine whether or not a message was tested.
  4. Clarified that "test not done" also means "Sieve system could not determine if a test was done".

Author's Address ✨

Cyrus Daboo

EMail: cyrus@daboo.name

okay bestie, the legal bit is here πŸ§ΎπŸ’– first up, the copyright line: Copyright (C) The IETF Trust (2008). πŸŽ€

This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights. 🌸

Now the disclaimer. It's in all caps on purpose, so read it carefully πŸ‘€

This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. πŸ’€

Intellectual Property

The IETF is not picking a side on whether any Intellectual Property Rights or other rights might apply to building or using the tech in this document, or how much of a license might be available under those rights. 🫢 It also doesn't claim to have done any independent digging to find out what rights exist. Info on how RFC documents handle rights lives in BCP 78 and BCP 79 🧚

If you want the paperwork, copies of IPR disclosures sent to the IETF Secretariat are available, along with any assurances of licenses. You can also find the results of anyone trying to get a general license or permission to use the proprietary rights for this spec, which is handy for implementers and users. Check the IETF online IPR repository at http://www.ietf.org/ipr. πŸ“‚βœ¨

Last but not least, the IETF really wants to hear from you πŸ¦‹ If you know of any copyrights, patents, patent applications, or other proprietary rights that might cover tech needed to implement this standard, tell the IETF at ietf-ipr@ietf.org. Spill the tea πŸ΅πŸ’…

πŸ“¦ where this page comes from