home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / elm-2.4-pl20.tar.Z / elm-2.4-pl20.tar / lib / parsarpwho.c < prev    next >
C/C++ Source or Header  |  1992-10-03  |  3KB  |  129 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: parsarpwho.c,v 5.1 1992/10/03 22:41:36 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.1 $   $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: parsarpwho.c,v $
  17.  * Revision 5.1  1992/10/03  22:41:36  syd
  18.  * Initial checkin as of 2.4 Release at PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** 
  24.  
  25. **/
  26.  
  27. #include "headers.h"
  28.  
  29. parse_arpa_who(buffer, newfrom, is_really_a_to)
  30. char *buffer, *newfrom;
  31. int is_really_a_to;
  32. {
  33.     /** try to parse the 'From:' line given... It can be in one of
  34.         two formats:
  35.         From: Dave Taylor <hplabs!dat>
  36.         or  From: hplabs!dat (Dave Taylor)
  37.  
  38.         Added: removes quotes if name is quoted (12/12)
  39.         Added: only copies STRING characters...
  40.         Added: if no comment part, copy address instead! 
  41.         Added: if is_really_a_to, this is really a 'to' line
  42.            and treat as if we allow embedded addresses
  43.     **/
  44.  
  45.     int use_embedded_addresses;
  46.     char temp_buffer[LONG_STRING], *temp;
  47.     register int i, j = 0, in_parens;
  48.  
  49.     temp = (char *) temp_buffer;
  50.     temp[0] = '\0';
  51.  
  52.     no_ret(buffer);        /* blow away '\n' char! */
  53.  
  54.     if (lastch(buffer) == '>') {
  55.       for (i=strlen("From: "); buffer[i] != '\0' && buffer[i] != '<' &&
  56.            buffer[i] != '('; i++)
  57.         temp[j++] = buffer[i];
  58.       temp[j] = '\0';
  59.     }
  60.     else if (lastch(buffer) == ')') {
  61.       in_parens = 1;
  62.       for (i=strlen(buffer)-2; buffer[i] != '\0' && buffer[i] != '<'; i--) {
  63.         switch(buffer[i]) {
  64.         case ')':    in_parens++;
  65.             break;
  66.         case '(':    in_parens--;
  67.             break;
  68.         }
  69.         if(!in_parens) break;
  70.         temp[j++] = buffer[i];
  71.       }
  72.       temp[j] = '\0';
  73.       reverse(temp);
  74.     }
  75.  
  76. #ifdef USE_EMBEDDED_ADDRESSES
  77.     use_embedded_addresses = TRUE;
  78. #else
  79.     use_embedded_addresses = FALSE;
  80. #endif
  81.  
  82.     if(use_embedded_addresses || is_really_a_to) {
  83.       /** if we have a null string at this point, we must just have a 
  84.           From: line that contains an address only.  At this point we
  85.           can have one of a few possibilities...
  86.  
  87.           From: address
  88.           From: <address>
  89.           From: address ()
  90.       **/
  91.         
  92.       if (strlen(temp) == 0) {
  93.         if (lastch(buffer) != '>') {       
  94.           for (i=strlen("From:");buffer[i] != '\0' && buffer[i] != '('; i++)
  95.         temp[j++] = buffer[i];
  96.           temp[j] = '\0';
  97.         }
  98.         else {    /* get outta '<>' pair, please! */
  99.           for (i=strlen(buffer)-2;buffer[i] != '<' && buffer[i] != ':';i--)
  100.         temp[j++] = buffer[i];
  101.           temp[j] = '\0';
  102.           reverse(temp);
  103.         }
  104.       }
  105.     }
  106.       
  107.     if (strlen(temp) > 0) {        /* mess with buffer... */
  108.  
  109.       /* remove leading spaces and quotes... */
  110.  
  111.       while (whitespace(temp[0]) || temp[0] == '"')
  112.         temp = (char *) (temp + 1);        /* increment address! */
  113.  
  114.       /* remove trailing spaces and quotes... */
  115.  
  116.       i = strlen(temp) - 1;
  117.  
  118.       while (i >= 0 && (whitespace(temp[i]) || temp[i] == '"'))
  119.        temp[i--] = '\0';
  120.  
  121.       /* if anything is left, let's change 'from' value! */
  122.  
  123.       if (strlen(temp) > 0) {
  124.         strncpy(newfrom, temp, STRING-1);
  125.         newfrom[STRING-1] = '\0';
  126.       }
  127.     }
  128. }
  129.