home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / lib / getaddrfrm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-16  |  2.6 KB  |  97 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: getaddrfrm.c,v 5.3 1993/05/16 20:55:52 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.3 $   $State: Exp $
  6.  *
  7.  *            Copyright (c) 1988-1992 USENET Community Trust
  8.  *            Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: getaddrfrm.c,v $
  17.  * Revision 5.3  1993/05/16  20:55:52  syd
  18.  * Fix bug where text following "<" within double-quote delimited comment
  19.  * is taken as an address.
  20.  * From: chip@chinacat.unicom.com (Chip Rosenthal)
  21.  *
  22.  * Revision 5.2  1992/11/07  20:05:52  syd
  23.  * change to use header_cmp to allow for linear white space around the colon
  24.  * From: Syd
  25.  *
  26.  * Revision 5.1  1992/10/03  22:41:36  syd
  27.  * Initial checkin as of 2.4 Release at PL0
  28.  *
  29.  *
  30.  ******************************************************************************/
  31.  
  32. /** 
  33.  
  34. **/
  35.  
  36. #include "headers.h"
  37. #include <ctype.h>
  38.  
  39. #ifdef USE_EMBEDDED_ADDRESSES
  40.  
  41. get_address_from(line, buffer)
  42. char *line, *buffer;
  43. {
  44.     /** This routine extracts the address from either a 'From:' line
  45.         or a 'Reply-To:' line.  The strategy is as follows:  if the
  46.         line contains a '<', then the stuff enclosed is returned.
  47.         Otherwise we go through the line and strip out comments
  48.         and return that.  White space will be elided from the result.
  49.     **/
  50.  
  51.     register char *s;
  52.     register int l;
  53.  
  54.     /**  Skip start of line over prefix, e.g. "From:".  **/
  55.     if ((s = index(line, ':')) != NULL)
  56.     line = s + 1;
  57.  
  58.     /*
  59.      * If there is a '<' then copy from it to '>' into the buffer.  We
  60.      * used to search with an "index()", but we need to handle RFC-822
  61.      * conventions (e.g. "<" within a double-quote comment) correctly.
  62.      */
  63.     for (s = line ; *s != '\0' && *s != '<' ; s += len_next_part(s))
  64.     ;
  65.     if (*s == '<') {
  66.     ++s;
  67.     while (*s != '\0' && *s != '>') {
  68.         if ((l = len_next_part(s)) == 1 && isspace(*s)) {
  69.         ++s; /* elide embedded whitespace */
  70.         } else {
  71.         while (--l >= 0)
  72.             *buffer++ = *s++;
  73.         }
  74.     }
  75.     *buffer = '\0';
  76.     return;
  77.     }
  78.  
  79.     /**  Otherwise, strip comments and get address with whitespace elided.  **/
  80.     s = strip_parens(line);
  81.     while (*s != '\0') {
  82.     l = len_next_part(s);
  83.     if (l == 1) {
  84.       if ( !isspace(*s) )
  85.         *buffer++ = *s;
  86.       s++;
  87.     } else {
  88.       while (--l >= 0)
  89.         *buffer++ = *s++;
  90.     }
  91.     }
  92.     *buffer = '\0';
  93.  
  94. }
  95.  
  96. #endif
  97.