home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / mail / addressing next >
Internet Message Format  |  1998-12-05  |  51KB

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!news.kodak.com!news-nysernet-16.sprintlink.net!news-in-east1.sprintlink.net!news.sprintlink.net!nntp2.cerf.net!news.idt.net!howland.erols.net!panix!news.panix.com!panix5.panix.com!eli!not-for-mail
  2. From: pogo@qz.little-neck.ny.us (Eli Pogonatus)
  3. Newsgroups: comp.mail.misc,news.admin.net-abuse.email,news.software.readers,comp.answers,news.answers
  4. Subject: Email Addressing FAQ (How to use user+box@host addresses)
  5. Supersedes: <eli$9811211603@qz.little-neck.ny.us>
  6. Followup-To: comp.mail.misc
  7. Date: 4 Dec 1998 23:43:02 GMT
  8. Organization: Some absurd concept
  9. Lines: 1251
  10. Approved: news-answers-request@MIT.EDU
  11. Expires: 29 Dec 1998 23:40:37 +0000
  12. Message-ID: <eli$9812041840@qz.little-neck.ny.us>
  13. NNTP-Posting-Host: panix5.nfs100.access.net
  14. Summary: How to add and use submailboxes to your email address.
  15. Xref: senator-bedfellow.mit.edu comp.mail.misc:47219 news.admin.net-abuse.email:303664 news.software.readers:56092 comp.answers:34141 news.answers:145923
  16.  
  17. Archive-name: mail/addressing
  18. Last-modified: (2 Jun 98 14:32:39)
  19. URL: http://www.qz.to/~eli/faqs/addressing.html
  20. Reason-for-last-modification: exim, qmail correction, trn4 update
  21. Reason-for-previous-modification: MMDF updated, Pine updated
  22.  
  23.    If you can add information PLEASE DO. This is Unix centric because I
  24.    have answers for Unix, not because I am trying to shun other
  25.    platforms.
  26.  
  27. Questions covered
  28.                                  __________
  29.  
  30.     1. What?
  31.     2. Why?
  32.     3. Things to consider
  33.     4. With qmail, how?
  34.     5. With sendmail, how?
  35.     6. With MMDF, how?
  36.     7. With exim, how?
  37.     8. With other MTAs, how?
  38.     9. With mutt, how?
  39.    10. With elm, how?
  40.    11. Using them in trn, how?
  41.    12. Using them in slrn, how?
  42.    13. Using them in tin, how?
  43.    14. Using them in nn, how?
  44.    15. Using them in Gnus, how?
  45.    16. Using them in knews, how?
  46.    17. Using them in MH, how?
  47.    18. Using them in pine, how?
  48.    19. Using them elsewhere, how?
  49.    20. Any other addressing suggestions?
  50.  
  51.      * Appendix
  52.          1. General format of a From: header
  53.          2. Filtering
  54.          3. A word on address types
  55.          4. Comprehensive plan for a new account
  56.          5. Verifying Email Addresses
  57.  
  58.    A good many of the examples in this FAQ are for a generic user, Alice,
  59.    who receives mail at bobs-home.com. Her "login" at that host is
  60.    "alice" and she uses boxes called "mail" and "news" in the localpart
  61.    of her address. (The word "localpart" comes from RFC 822 which defines
  62.    the now standard internet email address. It refers to the portion of
  63.    the email address before the "@".) Bobs-home.com uses sendmail, and
  64.    the examples reflect that.
  65.  
  66.    I find this a slightly more interesting way of giving examples than
  67.    the crude "localpart@fully.qualified.domain.name" and
  68.    "localpart@hostname.tld" that earlier versions of this FAQ used.
  69.  
  70. Questions and answers:
  71.                                  __________
  72.  
  73.     1. What?
  74.  
  75.        Mail transfer agents (MTAs) usually deliver mail to a single
  76.        location for each user on the system. There are ways of having
  77.        mail sent to more than one email address being delivered to the
  78.        same user. The simplest conceptually is a mail alias. Aliases
  79.        affect the whole machine and generally can only be set up by
  80.        administrators. This is not convenient for anyone involved. So
  81.        some MTAs have special ways of creating user level aliases. To
  82.        keep these from interfering with other aspects of mail on the
  83.        machine, these addresses are the username with a piece of
  84.        punctuation and a boxname appended.
  85.                               ___________________
  86.  
  87.     2. Why?
  88.  
  89.        Traditionally it has been useful for special sorting of mail, eg
  90.        casanova+anna@love.org, casanova+beth@love.org,
  91.        casanova+cathy@love.org, etc. so that each of Anna, Beth, and
  92.        Cathy send mail to a particular address and it gets treated
  93.        specially. These days it is becoming popular as a way of providing
  94.        special filtering (such as with procmail) on email addresses
  95.        exposed to insecure channels such as Usenet.
  96.  
  97.        Nancy McGough's Filtering Mail FAQ, available at the URLs below,
  98.        is a good start to finding out how to filter once you have the use
  99.        of these addresses. See also the appendix of this FAQ.
  100.  
  101.         FAQ "launchers" for the Filtering Mail FAQ:
  102.  
  103.                o
  104.                  http://www.ii.com/internet/faqs/launchers/mail/filtering-
  105.                  faq/
  106.                o http://www.best.com/~ii/faqs/archive/mail/filtering-faq/
  107.  
  108.         FTP sites for the Filtering Mail FAQ:
  109.  
  110.                o
  111.                  ftp://rtfm.mit.edu/pub/usenet/news.answers/mail/filtering
  112.                  -faq (and at the rtfm mirror sites)
  113.                o ftp://ftp.netusa.net/users/eli/mail.filtering-faq.txt
  114.                  (not strongly recommended)
  115.                               ___________________
  116.  
  117.     3. Things to consider
  118.  
  119.        For these to be useful you really must have several things working
  120.        together. Some of these things require system administrator
  121.        privileges to implement, if they are not working on your system
  122.        already, some do not. Some programs are as easy to configure as
  123.        adding a line by hand to the headers shown, others require
  124.        patching the code and recompiling. Hopefully the patches will
  125.        become part of the official distributions, when needed, to prevent
  126.        too much duplication of effort.
  127.  
  128.        Of primary importance, your system will need a mail transfer agent
  129.        (MTA) that can understand these addresses when there is an attempt
  130.        to give them to the system. Installing the MTA is definitely a
  131.        task for a system administrator. In some cases, configuring the
  132.        MTA will be as well.
  133.  
  134.        As a secondary, but not much less important, concern you will need
  135.        to be able to configure the various user-level mail handing
  136.        programs to use these aliases. There has not been a lot of
  137.        interest in these in the past, so very few programs make it easy
  138.        to do. The interest in filtering spam sent to addresses culled
  139.        from Usenet has made configuring news posters my primary concern
  140.        for this. I would like to add Q&As for mail user agents (MUAs),
  141.        those programs that generally act as a user interface to mail, but
  142.        I do not have a strong familiarity with any myself.
  143.  
  144.        As a last concern, you will want to know how to filter and sort
  145.        mail for maximum effectiveness. The appendix currently has that
  146.        information. Stephen R. van den Berg's procmail utility, available
  147.        in source form at
  148.        <URL:ftp://ftp.informatik.rwth-aachen.de/pub/packages/procmail/>,
  149.        is probably the best tool around. I found it difficult to learn
  150.        without lots of well-documented examples, so I have tried to
  151.        provide examples here.
  152.                               ___________________
  153.  
  154.     4. With qmail, how?
  155.  
  156.        Qmail is an MTA.
  157.  
  158.        Dave Sill <de5@sws5.ctd.ornl.gov> told me that with qmail all
  159.        Alice has to do is "touch ~/.qmail-news" to indicate that she
  160.        wants to receive mail at <alice-news@bobs-home.com>. Or she can
  161.        put the name of a mailbox in the file and mail will be delivered
  162.        there. If she doesn't have the .qmail-news file mail will normally
  163.        be bounced. She can also use a .qmail-default file to catch any
  164.        other case.
  165.  
  166.        If her .qmail is a single line consisting of just "#" all her mail
  167.        will silently be dropped. This might be a useful way to force
  168.        people to only send mail to her sub-boxes. She should be sure to
  169.        have files specified for her other mail, however. Since silently
  170.        discarding mail is the same as getting it and not responding (to
  171.        an outside observer), arranging to have the mail bounce might be
  172.        more useful. She could put a single line consisting of "| exit
  173.        100" there which will send a bland bounce message in the typical
  174.        qmail fashion.
  175.  
  176.        This is a user level configuration; it creates boxes of the form
  177.        <alias-boxname@bobs-home.com>.
  178.  
  179.        (If your site already uses '-' in usernames, you may wish to chage
  180.        the delimiter to another character. This is done at compile time.
  181.        Version 1.00, change the value of USEREXT_BREAK in conf-unusual.h.
  182.        Version 1.01, change the file "conf-break". Without this a user
  183.        called "me-too" would mask some of the suffix space for a user
  184.        called "me".)
  185.                               ___________________
  186.  
  187.     5. With sendmail, how?
  188.  
  189.        Sendmail is an MTA.
  190.  
  191.        Phil Edwards <pedwards@cs.wright.edu> talked about how to do it
  192.        with sendmail. Quoting him, because it doesn't paraphrase well,
  193.        "The usual setup is in ruleset 5, consisting of a couple lines
  194.        like
  195.  
  196.  
  197.         R$+ + *         $#local $@ $&h $: $1
  198.         R$+ + $*        $#local $@ $2 $: $1 + *
  199.  
  200.    with another one or two later on in the same ruleset. (I'm doing this
  201.        from memory; it'll probably differ from your .cf.) From there,
  202.        it's up to your local delivery program." He suggests using
  203.        procmail as the local delivery program; refer to the procmail
  204.        installation instructions for (a little) more information.
  205.  
  206.        This is an admin level configuration; it creates boxes of the form
  207.        <alias+boxname@bobs-home.com>. Once sendmail is configured, usage
  208.        of the mailboxes is user controlled. Recent releases of sendmail
  209.        come with this working already. (You can try to send yourself mail
  210.        at login+boxname to see if this is already set up on your system.
  211.        If not, you'll need to contact your system administrator.)
  212.                               ___________________
  213.  
  214.     6. With MMDF, how?
  215.  
  216.        MMDF is an MTA.
  217.  
  218.        Jerry Sweet, maintainer of the MMDF FAQ, has provided this
  219.        detailed answer.
  220.  
  221.      MMDF has long had an addressing feature of the form
  222.      "mailbox=string", which causes a message so addressed to be
  223.      delivered to "mailbox". The whole address, including the "=string"
  224.      part, appears in the $(address) variable for use in your
  225.      .maildelivery file.
  226.  
  227.      An application note on how to use MMDF's "=" addressing feature to
  228.      pre-sort incoming mail is available at this URL:
  229.  
  230.      http://www.irvine.com/~mmdf/auto-sort/index.html
  231.  
  232.      Note that MMDF doesn't preserve the "=string" information for use
  233.      following delivery, so all handling of the $(address) information
  234.      must take place at delivery time, using the .maildelivery file. So,
  235.      in order to take advantage of MMDF's "=" addressing feature, you
  236.      must use local delivery as opposed to POP delivery. (In other
  237.      words, you need a login account on the same host that runs MMDF.)
  238.  
  239.      For detailed information about using the "=" feature in one's
  240.      $HOME/.maildelivery file, refer to the MMDF maildelivery(5) on-line
  241.      man page.
  242.  
  243.        This is a user level configuration; it creates boxes of the the
  244.        form <alias=boxname@bobs-home.com>.
  245.                               ___________________
  246.  
  247.     7. With exim, how?
  248.  
  249.        Exim is a MTA.
  250.  
  251.        _Dom Mitchell <hdm@demon.net> provides this method._
  252.  
  253.      First, you must find the directors section of the exim
  254.      configuration file. In it, you will find a director like this:
  255.      (it's from the default configuration file, most people should have
  256.      it)
  257.  
  258.  
  259.     userforward:
  260.       no_verify,
  261.       driver = forwardfile;
  262.       check_ancestor,
  263.       file = .forward,
  264.     # filter
  265.  
  266.      You must then change it to look like this: (look in the exim manual
  267.      for details)
  268.  
  269.  
  270.     userforward:
  271.       no_verify,
  272.       suffix = "-*",
  273.       suffix_optional,
  274.       driver = forwardfile;
  275.       check_ancestor,
  276.       file = .forward,
  277.       filter
  278.  
  279.      This will enable username-extension for any value of extension. But
  280.      it will still get dropped into your default mailbox. To do more
  281.      with this, you can use exim's built in filtering. You must create a
  282.      ~/.forward file with the following first line:
  283.  
  284.  
  285.     # Exim filter
  286.  
  287.      And you can then use rules like the following to save mail into
  288.      different mailboxes:
  289.  
  290.  
  291.     if $local_part_suffix is "-foo"
  292.     then
  293.       save $home/Mail/foo-folder
  294.     elif $local_part_suffix is "-bar"
  295.     then
  296.       pipe "/usr/local/mh/lib/rcvstore +bar"
  297.     endif
  298.                               ___________________
  299.  
  300.     8. With other MTAs, how?
  301.  
  302.        Nobody responded with smail, exim, etc solutions.
  303.  
  304.        If you are using the Andrew Messaging System (AMS), which you
  305.        probably are if you have any other Andrew stuff on your system,
  306.        then you have all of this already. In fact AMS introduced the
  307.        concept. Read the documentation on FLAMES to find out how to use
  308.        this.
  309.                               ___________________
  310.  
  311.     9. With mutt, how?
  312.  
  313.        Mutt is a MUA.
  314.  
  315.        To change the from header, Alice in her .muttrc defines additional
  316.        lines with the command "my_hdr":
  317.  
  318.  
  319. my_hdr From: alice+mail@bobs-home.com (Alice)
  320.  
  321.        To just change the Reply-to: header, she can use:
  322.  
  323.  
  324. my_hdr Reply-To: alice+mail@bobs-home.com (Alice)
  325.                               ___________________
  326.  
  327.    10. With elm, how?
  328.  
  329.        Elm is a MUA.
  330.  
  331.        Elm stores extra headers to be used in mail in a .elm/elmheaders
  332.        file in her home directory. She just needs to add a From: and/or
  333.        Reply-To: header in that file and it will be used automatically.
  334.        The headers should be properly formatted for mail. The appendix
  335.        has sample formats acceptable for a from line.
  336.                               ___________________
  337.  
  338.    11. Using them in trn, how?
  339.  
  340.        Trn is a newsreader.
  341.  
  342.        Trn uses two environment variables, NEWSHEADER and MAILHEADER, to
  343.        control the headers that appear in posts and replies respectively.
  344.        For the default values Alice can read the man page for her copy of
  345.        trn. In the comprehensive plan for a new account there is a sample
  346.        configuration for trn. Suffice to say that she can add a from
  347.        header herself with those variables, or she can add one by hand
  348.        every time she sends mail or news. (I use a combination approach
  349.        myself.)
  350.  
  351.        Note that newer versions of trn can be controlled by a user level
  352.        configuration file to do this stuff, so she doesn't need to
  353.        clutter the environment. The documentation should cover this.
  354.  
  355.        At compile time it is possible to make the inews distributed with
  356.        trn4 "lax". Just define "LAX_INEWS" in config.h and recompile.
  357.        When the inews is "lax" it will check $USER and check $LOGNAME (in
  358.        that order) first for username.
  359.                               ___________________
  360.  
  361.    12. Using them in slrn, how?
  362.  
  363.        Slrn is a newsreader.
  364.  
  365.        Alice can add to her .slrnrc:
  366.  
  367. username "alice-news"
  368.  
  369.    With newer versions of slrn, she can set them per-group with the
  370.        article_mode_hook in the .slrn.sl file.
  371.                               ___________________
  372.  
  373.    13. Using them in tin, how?
  374.  
  375.        Tin is a newsreader.
  376.  
  377.        Some versions of tin use the USER environment variable to generate
  378.        the local part of the email address. Here are two aliases
  379.        resetting it just while using tin:
  380.  
  381.         csh or tcsh
  382.                 alias tin "env USER=alice+news tin"
  383.  
  384.         ksh, bash, or zsh
  385.                 alias tin="env USER=alice+news tin"
  386.  
  387.        If you already have a tin alias, it will not be used. Both aliases
  388.        will still allow you to give arguments to tin normally.
  389.  
  390.        Apparently there are some versions of the "unofficial" tin
  391.        floating about that would allow her to set a "forged" address from
  392.        the menu of configuration options. These are probably not too
  393.        commonly installed.
  394.                               ___________________
  395.  
  396.    14. Using them in nn, how?
  397.  
  398.        Nn is a newsreader.
  399.  
  400.        As in trn, Alice can add the from line by hand while posting or
  401.        configure nn to add them all the time. To get the latter, she
  402.        would add this to her .nn/init file:
  403.  
  404.  
  405. set news-header From: Alice <alice+news@bobs-home.com>
  406.  
  407.        She should be careful using semicolons (;) in it, unless escaped
  408.        they separate lines. The appendix has sample formats acceptable
  409.        for a from line. There is a mail-header setting for replies which
  410.        works the same way. In an over-zealous interpretation of RFC 1036,
  411.        nn will add a sender header to her posts with her un-boxed
  412.        address. I don't know any way around this. Using my inews may
  413.        work, but I have not tried.
  414.                               ___________________
  415.  
  416.    15. Using them in Gnus, how?
  417.  
  418.        Gnus is a newsreader and MUA.
  419.  
  420.        To change them in news she adds to her .gnus:
  421.  
  422. (setq message-default-news-headers
  423.       "From: Alice <alice+news@bobs-home.com>\n")
  424.  
  425.    For news and mail she can change message-default-headers instead. The
  426.        appendix describes the consideration for a From: header.
  427.  
  428.        If she would also use Gnus to read and filter your mail, she can
  429.        add an entry like the following to nnmail-split-fancy:
  430.  
  431.  
  432. ("to" "alice\\+news"
  433.   (| ("subject" "re:.*" "misc")
  434.      ("references" ".*@.*" "misc")
  435.      "spam"))
  436.  
  437.        This says that all mail to this address is suspect, but if it has
  438.        a Subject that starts with a Re: or has a References header, it's
  439.        probably ok, and will be put in the "misc" group. All the rest
  440.        goes to the "spam" group. This combines filters I use with those
  441.        used by Tim Pierce.
  442.  
  443.        This will sort virtually everything into the right group. She
  444.        still must check the "spam" group from time to time to check for
  445.        legitimate mail, though.
  446.  
  447.        See the Info documentation for nnmail-split-fancy for details and
  448.        variations.
  449.  
  450.        Mark T. Gray offers this further advice:
  451.  
  452.      Also gnus rather unfortunately will insert a Sender: line if it
  453.      finds that the From: line has a different username than it thinks
  454.      it should. To correct this put the following function redefinition
  455.      in your .gnus file:
  456.  
  457.  
  458. (defun message-make-sender ()
  459.   "Return the \"real\" user address.
  460. This replaces the function in message.el which tries to ignore all
  461. user modifications, and give as trustworthy answer as possible."
  462.   (cadr (mail-extract-address-components (message-fetch-field "from"))))
  463.  
  464.        It basically will return the same name as you stuck in her From:
  465.        field above and gnus is then happy to leave out the Sender: line.
  466.        Era Eriksson points out that this behavior is a configurable
  467.        option of Gnus:
  468.  
  469.  
  470. (nconc message-syntax-checks '((sender . disabled)) )
  471.  
  472.      This will preserve any existing overrides for message-syntax-checks
  473.      by merely adding (sender . disabled) to the end of any preset
  474.      values. If the variable is already being set e.g. in your site-wide
  475.      initialization files, you should still be able to use this without
  476.      clobbering anything.
  477.  
  478.        Another very useful function to put in her .gnus is the following
  479.        hook which will query the user for the alias to add on the
  480.        username whenever she sends a message:
  481.  
  482.  
  483. (defun my-address-choice ()
  484.   "This function chooses which alias-suffix to use"
  485.   (interactive)
  486.   (let ((alias-suffix (read-string "Which alias-suffix: ")) (alias))
  487.     (setq alias
  488.            (concat user-login-name "+" alias-suffix "@bobs-home.com")
  489.           mail-default-reply-to alias
  490.           user-mail-address     alias)
  491.     (message "%s" alias)))
  492.  
  493. (add-hook 'message-header-setup-hook 'my-address-choice)
  494.  
  495.        One person I have corresponded with is uncertain that will work
  496.        and believes it to be of dubious value anyway. Caveat emptor. All
  497.        of this question was written with Gnus 5.x in mind. I don't know
  498.        how much will apply to earlier versions.
  499.                               ___________________
  500.  
  501.    16. Using them in knews, how?
  502.  
  503.        Knews is a newsreader.
  504.  
  505.        David Kennedy says that to use these, Alice needs to put a line in
  506.        the Knews file like:
  507.  
  508.  
  509. Knews.mailName:         alice+news
  510.  
  511.        He also offers the warning "knews = executable, Knews = config
  512.        file." David was using version 0.9.8 when he offered the advice.
  513.                               ___________________
  514.  
  515.    17. Using them in MH, how?
  516.  
  517.        Answer submitted by Philip Guenther. I had thought that MH was an
  518.        MTA/MUA, but apparently it has a news section or I am confused.
  519.  
  520.        If you already have a components file for comp(1), then you just
  521.        need to add a Reply-To: or From: line to it. Be aware that if you
  522.        add a From: line then a Sender: line with your plain address will
  523.        be added by post(8), so your plain address will appear somewhere
  524.        in the message.
  525.  
  526.        If you don't already have a components file then create on in your
  527.        MH mail directory (probably $HOME/Mail), that contains:
  528.  
  529.  
  530. To:
  531. Cc:
  532. Subject:
  533. --------
  534.  
  535.        then follow the previous directions. In order for replies and
  536.        forwards to have the additional header you'll need to create or
  537.        edit replcomp and forwcomp file, and then tell repl and forw to
  538.        use them by editing your .mh_profile to include lines like:
  539.  
  540.  
  541. repl: -form replcomp
  542. forw: -from forwcomp
  543.  
  544.        For the default entries for those file check the repl and forw
  545.        manpages.
  546.                               ___________________
  547.  
  548.    18. Using them in pine, how?
  549.  
  550.        Pine is a MUA and newsreader.
  551.  
  552.        Pine tries to protect users from details and folly/ignorance, so
  553.        it is not easy. It requires editing the source code and
  554.        recompiling. If you feel up to it, here's how to do it.
  555.  
  556.        Edit the file pine/osdep/os-xxx.h of the source where xxx is the
  557.        3-letter abbreviation for your platform. Uncomment out the section
  558.        which applies to "ALLOW_CHANGING_FROM". Compile. Run it. Go to the
  559.        pine configuration control/menu and add an entry in
  560.        "customized-hdrs" for your new From: header. The appendix has
  561.        sample formats acceptable for a from line.
  562.  
  563.        Nancy McGough has a good web page on this that goes into more
  564.        detail. See it at either
  565.        <URL:http://www.ii.com/internet/messaging/pine/changing_from/> or
  566.        at
  567.        <URL:http://www.best.com/~ii/internet/messaging/pine/changing_from
  568.        />.
  569.                               ___________________
  570.  
  571.    19. Using them elsewhere, how?
  572.  
  573.        Well, if Alices uses sendmail directly to send mail (as I often
  574.        do) it is pretty obvious how. Otherwise, I am not sure. Netscape
  575.        and other programs which ask her to provide her own address will
  576.        doubtlessly accept these addresses readily.
  577.  
  578.        If she uses a program which has inews inject news into an NNTP
  579.        server, you might find the mini inews that I have hacked up
  580.        useful. It works like inews with programs that use it in one of
  581.        these forms:
  582.  
  583.           + inews -h < file (new inews)
  584.           + inews < file (old inews)
  585.           + inews -h file (new inews)
  586.           + inews file (old inews)
  587.        Anything that counts on command line options working is going to
  588.        be disappointed. Older versions of lynx and all versions of rn,
  589.        trn and nn that I know use inews in this fashion.
  590.  
  591.        This mini inews is from nn by way of lynx and has a number of
  592.        hacks and bug fixes by me. Of primary concern is that it is now
  593.        influenced by a NEWSMAILBOX environment variable when generating
  594.        the From: header. If you would like to use it, the source is kept
  595.        at ftp://ftp.netusa.net/users/eli/mini-inews.tgz in a tar/gzip
  596.        file.
  597.  
  598.        Alice would use one of these two set ups with this:
  599.          A. In her .login or her shell rc file (.cshrc or .tcshrc) for
  600.             csh or tcsh she would have:
  601.             setenv NEWSMAILBOX +news
  602.          B. For sh/ksh/bash/zsh she would have this in her .profile:
  603.             NEWSMAILBOX=+news
  604.             export NEWSMAILBOX
  605.                               ___________________
  606.  
  607.    20. Any other addressing suggestions?
  608.  
  609.        RFC822 is a long and complex document for those without strong
  610.        computer science backgrounds. Parts of it will be understandable
  611.        to most who read it, parts will not. Among other things it
  612.        specifies how email addresses can be formatted. News and SMTP mail
  613.        use RFC822 addresses. If she changes her address to one that is
  614.        equivalent but written differently, she may be able to use
  615.        procmail or another filtering tool process them.
  616.  
  617.        In particular the case sensitivity (upper vs. lower) of the
  618.        localpart (that which comes before the @ reading left to right) is
  619.        at the option of the destination machine. So if her MTA is (most
  620.        are) case insensitive for those addresses, she can change the case
  621.        of her name and all other mailers should preserve that
  622.        capitalization change. Humans typing the name tend not to be.
  623.  
  624.        Many mailers will preserve any "comments" included in an email
  625.        address. RFC822 defines a comment:
  626.  
  627.  
  628. comment     =  "(" *(ctext / quoted-pair / comment) ")"
  629. ctext       =  <any CHAR excluding "(", ")", "\" & CR, & including
  630.                 linear-white-space>
  631. quoted-pair =  "\" CHAR                     ; may quote any char
  632. linear-white-space =  1*([CRLF] LWSP-char)  ; semantics = SPACE
  633.                                             ; CRLF => folding
  634.  
  635.         CHAR
  636.                 7-bit character
  637.  
  638.         LWSP
  639.                 linear whitespace: TAB and SPACE
  640.  
  641.         CR
  642.                 carriage return, an ASCII control character
  643.  
  644.         LF
  645.                 line feed, an ASCII control character
  646.  
  647.        This is not very legible to the typical human. What it means is a
  648.        comment may contain any character, but some -- "(" ")" "\" CR --
  649.        must be "backslash escaped". That just means put a backslash (it
  650.        is "\" and not "/") in front of characters whose special meanings
  651.        that need to be escaped.
  652.  
  653.        Mostly. There is also that bit that comments may contain other
  654.        comments; this will preclude using regular expressions to match
  655.        addresses. Basically this translates to mean that your parentheses
  656.        must match in the normal manner or else should be backslash
  657.        escaped. So some valid comments are
  658.  
  659.  
  660. (hi-ya @lice here)
  661.  
  662. (This is //-\\lice)
  663.  
  664. (Let's (recurse (and (again (and (again (and (I'm (bored (now))))))))))
  665.  
  666. (\) whee)
  667.  
  668.    And some invalid comments would be
  669.  
  670. (\/\/\/\/\)
  671.  
  672. ()ops)
  673.  
  674. (Spiff()
  675.  
  676.    Now, if that were not ugly enough, RFC822 says that there can be
  677.        whitespace or comments by any delimiter. The delimiters are
  678.  
  679.           ( ) < > @ , ; : \ " . [ ]
  680.  
  681.        So the following are all legal and equivalent addresses for me:
  682.  
  683. < eli @ netusa . net >
  684.  
  685. <eli(jah)@netusa.net>
  686.  
  687. < eli(Elijah)@netusa(not associated with usa.net).net >
  688.  
  689. (Elijah) <eli@(dougs-home)netusa.net>
  690.  
  691. < eli @ (the raw IP for mail (and thus subject to change)) [204.141.0.25] >
  692.  
  693. < eli @ (a subtler variation on the above) [204.141.25] >
  694.  
  695. <eli (Pogonatus (latin for <the bearded>))@ (qz (pronounced (queasy) ) \
  696.  .little-neck (I did not want that, but RFC1480 required it) .ny (New \
  697.  F%@!: York) .us (USA) or ) netusa (Located on Long Island) . net> (Elijah)
  698.  
  699.    Alice will find that a lot of mailers are not RFC822 compliant by
  700.        trying some of those out, especially that last one. Most mailers
  701.        seem happy to accept and preserve addresses like the second one
  702.        from the top, so that may be a good way for Alice to modify her
  703.        address for filtering purposes. "Preserve" does not mean that the
  704.        comment will be in the same place, just that it will be included.
  705.  
  706.        The URL (uniform resource locator) mailto: scheme employs an
  707.        "RFC822 addr-spec" address in the scheme specific part. According
  708.        to my reading of the relevant RFCs, this means you can use
  709.        comments in mailto: addresses, but the "%", "+", and whitespace
  710.        characters should be "percent escaped". This escaping works by
  711.        having a % followed by the hexadecimal value of the character so
  712.  
  713.         %
  714.                 => %25
  715.  
  716.         +
  717.                 => %2b
  718.  
  719.         <space>
  720.                 => %20
  721.  
  722.        Note that the "<" and ">" address delimiters should not be used in
  723.        a URL. The URL format itself precludes the need for them.
  724.  
  725.        Other people disagree with my reading of the RFCs on this issue.
  726.        They think comments are not allowed at all in the mailto: scheme.
  727.        And it is true that some of the more obscure web browsers
  728.        incorrectly percent escape parentheses, thus destroying the
  729.        address. I think all versions of Netscape, Explorer, Mosaic, and
  730.        Lynx get it right, but use with caution.
  731.                     ___________________________________
  732.  
  733. Appendix
  734.                                  __________
  735.  
  736.    General format of a From: header
  737.  
  738.    Here are the three generally accepted formats for a From: line. These
  739.    are actually just special cases of RFC 822 addresses appearing after
  740.    the string "From: ". RFC 1036 specifies that only one of these
  741.    variations should be used for news. I have tried other variations in
  742.    mail and seen weird things happen when people with combined mail and
  743.    news readers try to reply.
  744.  
  745.  
  746. From: alice+news@bobs-home.com (Alice)
  747. From: Alice <alice+news@bobs-home.com>
  748. From: alice+news@bobs-home.com
  749.  
  750.    localpart will be your username+box; the fully qualified domain name
  751.    is the full name of a machine you receive mail at; the name field has
  752.    whatever "full name" you want to use. See the other suggestions
  753.    question for more information on RFC 822 addresses.
  754.                                  __________
  755.  
  756.    Filtering
  757.  
  758.    Well, now that Alice has a means of marking addresses for different
  759.    handling, it is entirely reasonable that she might want some advice on
  760.    how to use the marks effectively. Nancy McGough's Filtering Mail FAQ
  761.    referenced earlier in this FAQ is a good place to start learning about
  762.    filtering tools. I am going to provide some advice here for what to
  763.    filter with. I have a filtering resource page that gives information
  764.    on the filters I use, including a link to an annotated version of my
  765.    procmailrc. The page is at
  766.    <URL:http://www.netusa.net/~eli/filtering.html>
  767.  
  768.    I have found it very effective to give addresses exposed to Usenet in
  769.    the form of a From: or Reply-To: line the most stringent filtering. I
  770.    use procmail to handle my filtering, and this is the exact recipe I
  771.    have for it (my Usenet posts go out from
  772.    <usenet-tag@qz.little-neck.ny.us>):
  773.  
  774.  
  775.         :0:
  776.         * ^TOusenet-tag@qz
  777.         * !^Subject:(.Re:|(.*[[({ -](was|Re):))
  778.         IN.junk
  779.  
  780.    IN.junk is a mbox file I check occasionally for false positives. Maybe
  781.    1-3% of it is false positives, often very easily distinguishable from
  782.    the other stuff by the subject line.
  783.  
  784.    For those unfamilar with regular expressions (REs), that recipe is
  785.    probably not very clear. Unfortunately REs are quite complicated and
  786.    beyond the scope of this document. Jeffrey Friedl has written a good
  787.    book about them, Mastering Regular Expressions published by O'Reilly
  788.    and Associates. Many other sources cover them in less detail. Check
  789.    your documentation for grep or egrep in particular. Be aware that most
  790.    egreps today are much more sophisticated than the one procmail claims
  791.    to be compatible with.
  792.  
  793.    In English, here's what that does. All mail sent to an address
  794.    containing the phrase "usenet-tag@qz" which gets delivered to me will
  795.    be tested for compliance with the second rule. The second rule says
  796.    any of that mail which does not have a subject which begins with "Re:"
  797.    or have a subject which anywhere in it contains a "[", "(", "{", " "
  798.    or "-" followed immediately by a "was:" or "Re:" is put into the junk
  799.    pile. The first part of the subject rule matches regular replies to
  800.    posts and so they do not get junked. The second part recognizes the
  801.    standard Usenet convention for changing a subject line, which is to
  802.    put the new subject in front and then leave the old one there
  803.    (sometimes parenthetically) after the word "was:".
  804.  
  805.    The types of mail this messes up on are those where someone takes the
  806.    time to note the address, and uses it to send new mail later. This
  807.    happens very infrequently in my experience. Tim Pierce and others have
  808.    advocated checking for headers left in by newsreaders when filtering
  809.    mail for Usenet addresses. This is subject to the same problem as my
  810.    technique, but is additionally dependent on people not replying from
  811.    copies found in DejaNews or Altavista and on relying upon newsreaders
  812.    to add headers not specified in any standards document. That second
  813.    bit makes it much too unreliable, in my opinion.
  814.  
  815.    A note about that recipe: My username is not "usenet" and that is not
  816.    a submailbox for me. With sendmail (at least how I had it configured,
  817.    YMMV with legacy sendmail.cf files) sub-boxing works just the same.
  818.    Other MTAs might not work that way: the box name may get canonicalized
  819.    out of the header. Mailers are not supposed to rewrite these headers,
  820.    but it happens all the time. In any case, Philip Guenther
  821.    <guenther@gac.edu> wrote on the procmail mailing list (to join, send
  822.    subscription requests to
  823.    <procmail-request@Informatik.RWTH-Aachen.DE>):
  824.  
  825.  
  826. Michael Ghens <michael@spconnect.com> writes:
  827. >I missed it, how does the + addressing get passed in
  828. >
  829. >as in michael+pgp@spconnect.com
  830.  
  831.  
  832. It shows up as $1 in your procmail, which you can then test with
  833. something like:
  834.  
  835.         ARG = $1
  836.  
  837.         :0
  838.         * ARG ?? ^^pgp^^
  839.         pgp-folder
  840.  
  841.         :0
  842.         * ARG ?? ^^cypher-punks^^
  843.         cypher-punks-folder
  844.  
  845.  
  846. You can't test $1 directly, thus the assignment to ARG.
  847.  
  848.    ^^ is a weird procmail-specific regexp anchor. ^ and $ work just as
  849.    well for what we want. (Gory details: ^ and $ match zero width
  850.    conditions near line ends, while ^^ matches zero width conditions near
  851.    string ends, much like \A and \Z in perl.) The main advantage of that
  852.    recipe is $1 is set to the correct subbox even for Bcc'ed stuff when
  853.    procmail is used as the local delivery agent from sendmail. (For
  854.    certain sendmail.cf configurations at least.)
  855.  
  856.    One can AND test together in a procmail recipe in a number of ways.
  857.    Including a number of separate * tests is one way, but it does not
  858.    allow if-then-else type structures easily. For those { ... } grouping
  859.    can be used. Here is an example for a submailbox named "news"
  860.    employing my subject rule.
  861.  
  862.  
  863.         ARG=$1
  864.  
  865.         # Rules to apply to Usenet responses.
  866.         :0
  867.         * ARG ?? ^news$
  868.         {
  869.           # Where to send stuff missing Re: or was: in the subject
  870.           :0:
  871.           * !^Subject:(.Re:|(.*[[({ -](was|Re):))
  872.           IN.junk
  873.  
  874.           # Where to send the rest of it.
  875.           :0:
  876.           IN.good
  877.         }
  878.                            _____________________
  879.  
  880.    A word on address types
  881.  
  882.    In the simple mail transport protocol (SMTP) there are two types of
  883.    sender address and two types of recipient address. This can be used
  884.    for all sorts of obfuscation, and often is. The types are,
  885.    respectively, the envelope addresses and the header addresses.
  886.  
  887.    Within the protocol, the difference between the two is that envelope
  888.    addresses are specified with protocol commands and header addresses
  889.    are specified as part of the mail data. There need not be any
  890.    correlation between a From: or To: in the headers and those from the
  891.    envelope. Most mailer delivery agents add a Return-Path: header that
  892.    has the envelope from address when delivering mail. Some delivery
  893.    agents add the envelope to address to a Received: header, but they do
  894.    not do it when there is more than one recipient at a site. If either
  895.    of the header to or from addresses are missing they will be added as
  896.    an Apparently-To: or Apparently-From: using the envelope addresses.
  897.  
  898.    Why the two different types? Well it turns out that this is really
  899.    useful for forwarding mail, especially for mailing lists. Mail sent to
  900.    a mailing list will be delivered with the envelope from set to the
  901.    list, the envelope to set to each member of the list, the header from
  902.    set to the sender of the message, and the header to set to the list.
  903.    Note that this is a convention, not a requirement. It makes a lot of
  904.    sense for a mailing list, if you think about it. Similar behavior is
  905.    used for blind carbon copied (BCC) mail.
  906.  
  907.    There is the problem however that people wishing to send bulk email
  908.    (legitimately or not) can just set up a mailing list and it all gets
  909.    delivered to the recipient without them knowing what address was used.
  910.    The implications of this on sub-box filtering should be obvious.
  911.  
  912.    Unless your mail delivery agent does your filtering, all mail to
  913.    desired mailing lists must be pre-filtered out and then all other
  914.    Bcc'ed mail must be considered suspect. Here is a sample procmailrc
  915.    for Alice if she were subscribed to several lists I read:
  916.  
  917.  
  918. # Process mail not specifically addressed to alice@bobs-home
  919. :0
  920. * !^TOalice@bobs-home
  921. {
  922.   # Sent by or to the quickcam driver developer list, a generic list
  923.   # example. Return-Path:, assuming your mailer adds it, is another
  924.   # good generic header to filter on. Some mailing lists are run by
  925.   # a special list user and so all lists from that machine will have
  926.   # the same Return-Path:. This will break things in some situations.
  927.   :0:
  928.   * ^(Sender|To):.*quickcam-drivers
  929.   IN.quickcam-list
  930.  
  931.   # Mail from the lynx developer's list -or- a Bcc'ed personal reply
  932.   # to mail from it. This is a filtering (dis)advantage of lists that
  933.   # modify the subject.
  934.   :0:
  935.   * ^Subject:.*LYNX-DEV
  936.   IN.lynx-list
  937.  
  938.   # From the procmail list. All smartlist mailing lists have a handy
  939.   # X-Loop header to filter on.
  940.   :0:
  941.   * ^X-Loop: procmail@informatik.rwth-aachen.de
  942.   IN.procmail-list
  943.  
  944.   # Remaining mail is either a Bcc or an unknown mailing list.
  945.   :0:
  946.   IN.bcc-suspect
  947. }
  948.  
  949.    With MMDF filtering or procmail as her local delivery agent and some
  950.    sendmail.cf magic, Alice can filter on the envelope address. For
  951.    procmail see the example above on the usage of $1. For MMDF she can
  952.    add to her .maildelivery file a line like:
  953.  
  954.  
  955. addr = | A "/path/to/procmail -a $(address) -d alice"
  956.  
  957.    This will enable procmail filtering on the envelope as above. Read the
  958.    man page for maildelivery(5) for more information on a MMDF
  959.    .maildelivery file.
  960.                            _____________________
  961.  
  962.    Comprehensive plan for a new account
  963.  
  964.    This is a plan of action Alice, mail id alice at bobs-home.com could
  965.    use. Bobs-home has sendmail configured to use + addresses, but not to
  966.    use procmail as a delivery agent. (So procmail cannot know the
  967.    envelope address.)
  968.  
  969.    Here is what she is going to do: bounce all mail addressed to
  970.    "alice@bobs-home", accept mail addressed to "alice+mail@bobs-home",
  971.    and filter mail to "alice+news@bobs-home". Then set the reply to for
  972.    all of her mail to "alice+mail@bobs-home.com" and send all of her
  973.    posts from "alice+news@bobs-home.com". This is hard to do on an old
  974.    account, because too many people know the regular address. With a new
  975.    account she can prevent them from ever getting into the habit of using
  976.    it.
  977.  
  978.    She starts off by creating this .forward file to invoke procmail on
  979.    all of her mail. The quotes used are an important part of this.
  980.  
  981.  
  982. "|IFS=' '&&exec /usr/local/bin/procmail -f-||exit 75 #alice"
  983.  
  984.    Here is a procmailrc that should do the filtering part. As yet this is
  985.    UNTESTED. The DEFAULT variable should be defined by procmail to her
  986.    system mailbox, setting it herself won't hurt, assuming she gets it
  987.    right.
  988.  
  989.  
  990. # The system mailboxes at bobs-home are in /var/spool/mail/.
  991. DEFAULT=/var/spool/mail/alice
  992.  
  993. # Where non-DEFAULT mailboxes live; Mutt uses $HOME/Mail/ by default.
  994. # Destination files in recipes will be relative to this unless they
  995. # start with a '/'. $HOME is set already.
  996. MAILDIR=$HOME/Mail
  997.  
  998. # Where to log.
  999. LOGFILE=$HOME/.procmaillog
  1000.  
  1001. # Set the shell, just to make sure it's /bin/sh
  1002. SHELL=/bin/sh
  1003.  
  1004. # Three line summary log for each piece of mail.
  1005. LOGABSTRACT=yes
  1006.  
  1007. # Addtionally, log the To: header. formail comes with procmail.
  1008. LOG=`formail -X To:`"
  1009. "
  1010.  
  1011. # Accept real mail
  1012. :0:
  1013. * ^TOalice\+mail@bobs-home
  1014. $DEFAULT
  1015.  
  1016. # Accept mailer daemon mail
  1017. :0:
  1018. * ^FROM_MAILER
  1019. $DEFAULT
  1020.  
  1021. # Filter news replies
  1022. # (The plus character in the address is "magical" in REs
  1023. #  and needs to be protected with a backslash)
  1024. :0
  1025. * ^TOalice\+news@bobs-home
  1026. {
  1027.         # Bad subject: not in reply form
  1028.         :0:
  1029.         * !^Subject:(.Re:|(.*[[({ -](was|Re):))
  1030.         IN.junk
  1031.  
  1032.         # Reply to an article
  1033.         :0:
  1034.         $DEFAULT
  1035. }
  1036.  
  1037. # Bounce remainder, saving a copy in junk, just in case. The EXITCODE is
  1038. # the value procmail will return to sendmail on exit. 67 is a sendmail
  1039. # specific value that will cause a bounce message to be sent.
  1040. EXITCODE=67
  1041. :0:
  1042. IN.junk
  1043.  
  1044.    Alice uses trn to read and post news, so she sets the NEWSHEADER and
  1045.    MAILHEADER environment variables. sh/ksh/bash/zsh commands that go
  1046.    into a .profile for this are:
  1047.  
  1048.  
  1049. # This is the default value of NEWSHEADER in 3.6 with a from line prepended.
  1050. NEWSHEADER='From: Alice <alice+news@bobs-home.com>
  1051. %(%[followup-to]=^$?:%(%[followup-to]=^%n$?:X-ORIGINAL-NEWSGROUPS: %n
  1052. ))Newsgroups: %(%F=^$?%C:%F)
  1053. Subject: %(%S=^$?%"\n\nSubject: ":Re: %S)
  1054. Summary:
  1055. Expires:
  1056. %(%R=^$?:References: %R
  1057. )Sender:
  1058. Followup-To:
  1059. %(%{REPLYTO}=^$?:Reply-To: %{REPLYTO}
  1060. )Distribution: %(%i=^$?%"Distribution: ":%D)
  1061. Organization: %o
  1062. Keywords: %[keywords]
  1063. Cc: \n\n'
  1064.  
  1065. # This is the default value of MAILHEADER in 3.6 with a from line prepended.
  1066. MAILHEADER='From: Alice <alice+mail@bobs-home.com>
  1067. To: %t
  1068. Subject: %(%i=^$?:Re: %S
  1069. %(%{REPLYTO}=^$?:Reply-To: %{REPLYTO}
  1070. )Newsgroups: %n
  1071. In-Reply-To: %i)
  1072. %(%[references]=^$?:References: %[references]
  1073. )Organization: %o
  1074. Cc:
  1075. Bcc: \n\n'
  1076.  
  1077. export NEWSHEADER MAILHEADER
  1078.  
  1079.    This will cause the Originator: header to be set to
  1080.    "alice@bobs-home.com", but since she is bouncing that address it
  1081.    shouldn't matter too much. If she really wanted to clean that up, she
  1082.    could use a different inews and Pnews. (Stuff that is posted and
  1083.    mailed using the Cc: header on a post will appear to be from the
  1084.    "alice+news" address.)
  1085.  
  1086.    Alice uses mutt to read and reply to mail, so she creates a .muttrc
  1087.    with the following line it it:
  1088.  
  1089.  
  1090. my_hdr From: Alice <alice+mail@bobs-home.com>
  1091.  
  1092.    When Alice wants to subscribe to mailing lists she will have to adjust
  1093.    her .procmailrc accordingly. She also can't get Bcc'ed mail as sent by
  1094.    most programs. As a last comment let me state that there is nothing
  1095.    inherently special about her using "+mail" and "+news" as the box
  1096.    names, it was just convient.
  1097.                            _____________________
  1098.  
  1099.    Verifying Email Addresses
  1100.  
  1101.    An often asked question in many newsgroups is "How can I verify an
  1102.    email address?" Sometimes people mean that they want to verify
  1103.    deliverability, sometimes they wish to verify valid syntax. The
  1104.    reasons for doing this vary from not wanting to accept invalid
  1105.    addresses in databases to wanting to discard all mail from invalid
  1106.    addresses. Neither verification variant is probably worth the effort.
  1107.    A sanity check might be worthwhile for catching obvious problems, but
  1108.    that is about it.
  1109.  
  1110.    Some of the techniques and pitfalls of the deliverability variant
  1111.    include:
  1112.  
  1113.      * Technique: "Verify that the destination machine name is real"
  1114.  
  1115.        Pitfalls: Between mailer exchange (MX records) redirections and
  1116.        wildcarded mailer exchanges for whole domains, a real address
  1117.        might be incorrectly flagged as bad. Combine that with temporary
  1118.        domain name service (DNS) and other transient problems that crop
  1119.        up and the complexity becomes apparent. Then you have to worry
  1120.        about routed addresses which have multiple hostnames to worry
  1121.        about, at least one of them probably not Internet accessible. UUCP
  1122.        bang ("!") paths are probably the best known variety of these.
  1123.  
  1124.      * Technique: "Use the SMTP VRFY command"
  1125.  
  1126.        Pitfalls: The most common pitfall with this is that most modern
  1127.        MTAs can be configured to not give out useful information in
  1128.        response to this or to the related EXPN command. Gateways,
  1129.        remailers, and various transient problems will further frustrate
  1130.        the would-be VRFYer.
  1131.  
  1132.      * Technique: "Attempt to mail to the address and check for a bounce"
  1133.        This sometimes includes actually sending mail, and sometimes just
  1134.        presenting a mail envelope to the mail server.
  1135.  
  1136.        Pitfalls: Some addresses never bounce mail even if it is an
  1137.        invalid address. Some addresses send faked bounces to some mail
  1138.        while still saving it for a recipient to read. Sometimes MTAs send
  1139.        informational transient error bounce messages to indicate the mail
  1140.        is spooled and delivery will be reattempted. These do not provide
  1141.        any information about validity of the address.
  1142.  
  1143.      * Technique: "Send mail to the address asking for a reply"
  1144.  
  1145.        Pitfalls: Getting a reply from this is the only way to be sure
  1146.        that an address was valid at the time you sent the mail. Since
  1147.        then, of course, the address could have become invalid. Not
  1148.        getting a reply doesn't help too much. Getting a bounce may help.
  1149.  
  1150.    The "check for bounce" tests are probably the best sanity check for
  1151.    address deliverability. Most addresses that bounce are invalid, most
  1152.    that don't are valid.
  1153.  
  1154.    The other variant, checking for valid syntax in an address, is doable,
  1155.    even when isolated from a network. It is not done easily however. Look
  1156.    at some of the valid address examples I gave earlier in this FAQ. The
  1157.    most pathological of the lot are probably these two:
  1158.  
  1159.  
  1160. < eli @ [ 204 . 141 . 25 ] >
  1161.  
  1162. <eli (Pogonatus (latin for <the bearded>))@ (qz (pronounced (queasy) ) \
  1163.  .little-neck (I did not want that, but RFC1480 required it) .ny (New \
  1164.  F%@!: York) .us (USA) or ) netusa (Located on Long Island) . net> (Elijah)
  1165.  
  1166.    The first one uses a domain literal, hence the [brackets]. Many people
  1167.    seem to think that it is fine to just use raw IP addresses in the
  1168.    route specification portion of an address. This is not true. Some
  1169.    mailers may accept it, but the proper notation uses brackets. Even
  1170.    when people do know that, they don't often know that in dot quad
  1171.    notation the third quad or both the second and third quads may be
  1172.    dropped if they are zeros. So "[127.1]" is equivalent to "[127.0.0.1]"
  1173.    and "[204.141.25]" is equivalent to "[204.141.0.25]".
  1174.  
  1175.    The second example is designed to break all regexps I have seen to
  1176.    check for a valid RFC 822 address. Jeffrey Friedl designed the most
  1177.    comprehensive one I have seen as an example for his book Mastering
  1178.    Regular Expressions. But because regular expressions may not match
  1179.    arbitrary paired nestings, e.g. properly matched parentheses, his
  1180.    effort was only designed to match two deep nesting. For other efforts
  1181.    to recognize addresses, that example includes six characters special
  1182.    in email addresses ( < > % @ ! : ) inside of comments in it. Not to
  1183.    mention all that whitespace, since it's allowed and improves
  1184.    readibility so much. :^)
  1185.  
  1186.    The two practical options are to write a full RFC 822 address parser
  1187.    or to "destructively" test a copy of the address. The first is not too
  1188.    difficult, but there are about three pages of BNF in RFC822 so it
  1189.    would probably take at least an afternoon's time to write. The second
  1190.    involves making a temporary copy of the address and then iteratively
  1191.    removing comments and other trouble- some things with say a regexp,
  1192.    and then feeding it to Friedl's verifier. Here's some perl code that
  1193.    should work for such a destructive preprocessor:
  1194.  
  1195.  
  1196. $copy = $address_to_test;
  1197.  
  1198.         $copy =~ s:\\.:a:g          ;    # replace \quoted stuff
  1199.         $copy =~ s:\\\n::gs         ;    # unfold lines
  1200.         $copy =~ s:"[^"]*":b:g      ;    # replace "quoted" stuff
  1201. while ( $copy =~ s:\([^()]*\)::g ) {;}   # (remove ((all) comments))
  1202.  
  1203.    The while loop removes nested comments one layer at a time. Friedl's
  1204.    code to check the address is available from his web pages:
  1205.    <URL:http://enterprise.ic.gc.ca/~jfriedl/regex/code.html>. It is about
  1206.    5k. If the copy is a syntactically valid address, then the original
  1207.    was as well.
  1208.  
  1209.    For a reasonable sanity check after my destructive rewriting, try
  1210.    this.
  1211.  
  1212.  
  1213.         $copy =~ s:\s+::g ;      # suppress whitespace
  1214.  
  1215. $lft = ($copy =~ y:<:<: ); # count <s
  1216. $rgt = ($copy =~ y:>:>: ); # count >s
  1217.  
  1218.    if (( $rgt != $lft ) || ( $lft < 0 ) || ( $lft > 1 )) {
  1219.                 print "Address has invalid encapsulation\n";
  1220. }
  1221. else {
  1222.         # extract from encapsulation, if any
  1223.         $copy =~ s:.*<([^>]*)>.*:$1: ;
  1224.  
  1225.    if ( $copy =~ m:\@\.|\.\.|\.$: ) {
  1226.                 print "Address has invalid dot placement\n";
  1227. }
  1228. elsif ( $copy =~ m:\@.*\@|^\@|\@$: ) {
  1229.                 # There are legal addresses this will reject, but they
  1230.                 # are mind-numbingly rare in practice. The most common
  1231.                 # form is illustrated in this routed address for me:
  1232.                 # <@alpha.netusa.net:eli@mail.netusa.net>
  1233.                 print "Address has dubious \@ usage\n";
  1234. }
  1235. elsif(!($copy =~ y:@:@:)) {
  1236.                 print "Address does not have an at sign\n";
  1237. }
  1238. elsif(!($copy =~ y:.:.:)) {
  1239.                 print "Address does not have a dot\n";
  1240. }
  1241. else {          print "Address is probably good.\n";  }
  1242.  
  1243. }
  1244.  
  1245.    People often try to make other tests, many of them ill-advised. One
  1246.    common one is testing for a known top level domain (TLD). There are a
  1247.    lot of these, so doing it right involves a lot of tests or a very
  1248.    large and probably slow regexp. And that ignores the fact that new
  1249.    ones get added every now and then. As I write this there is the case
  1250.    of Zaire. Until recently it was ".zr", but now that Laurent Kabila has
  1251.    forced Mobutu Sese Seko out, the country has been renamed the
  1252.    Democratic Republic of Congo. It is not unreasonable to expect that a
  1253.    new TLD might be added for it.
  1254.  
  1255.    Another common but unreliable test is checking for spaces. Besides the
  1256.    case I have often illustrated of whitespace being allowed around the
  1257.    delimiting characters, it is legitimate to have spaces in the local
  1258.    part of an address. Try sending mail to my
  1259.    "echo request"@qz.little-neck.ny.us address. Don't worry about the
  1260.    subject, but put just the word "ping" in the body. This toy will reply
  1261.    from the address it receives your mail from. Thus you can see if your
  1262.    mailer is breaking things, such as sending the mail to "request@qz"
  1263.    instead.
  1264.      _________________________________________________________________
  1265.  
  1266.    Comments on this FAQ? Send me mail.
  1267.  
  1268.