home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / getval.c < prev    next >
Text File  |  1994-09-25  |  4KB  |  171 lines

  1. /*  getval.c   These routines to extract information from mail/news headers.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. #include "uucp.h"
  26. #include <ctype.h>
  27.  
  28. #define BUFFSIZE    256
  29.  
  30. static char vtemp[BUFFSIZE];
  31.  
  32. #ifndef _OSK
  33. char *memset();
  34. #endif
  35.  
  36. char *cutspace();
  37.  
  38.  
  39. /* getval  --parse mail/news header line and return value */
  40.  
  41. char *getval (line)
  42. char *line;
  43. {
  44.      register char *p;
  45.  
  46.      memset (vtemp, '\0', sizeof (vtemp));
  47.  
  48.      /* Return value between <> if we find them */
  49.      if ((p = strchr (line, '<')) != NULL)
  50.        {
  51.           strncpy (vtemp, &p[1], BUFFSIZE);
  52.  
  53.           /* be sure string is NULL-terminated */
  54.           vtemp[BUFFSIZE - 1] = '\0';
  55.  
  56.           if ((p = strchr (vtemp, '>')) != NULL)
  57.                *p = '\0';
  58.        }
  59.  
  60.      /* Otherwise, return the string following the colon */
  61.      else
  62.        {
  63.           p = strchr (line, ':');
  64.           p++;
  65.           p = skipspace (p);
  66.           strncpy (vtemp, p, BUFFSIZE);
  67.           p = vtemp;
  68.  
  69.           /* be sure string is NULL-terminated */
  70.           vtemp[BUFFSIZE - 1] = '\0';
  71.  
  72.           while (*p  && !isspace (*p))
  73.                p++;
  74.  
  75.           *p = '\0';
  76.        }
  77.  
  78.      return (vtemp);
  79. }
  80.  
  81.  
  82.  
  83. /* getrealname  --get real name from mail/news header */
  84.  
  85. char *getrealname (line)
  86. char *line;
  87. {
  88.      register char *p;
  89.  
  90.      memset (vtemp, '\0', sizeof (vtemp));
  91.  
  92.      /* From: real name here <EMail address> */
  93.      if (strchr (line, '<') != NULL)
  94.        {
  95.           p = strchr (line, ':');
  96.           p++;
  97.           p = skipspace (p);
  98.  
  99.           if (*p == '\"')
  100.                p++;
  101.  
  102.           strncpy (vtemp, p, BUFFSIZE);
  103.  
  104.           /* be sure string is NULL-terminated */
  105.           vtemp[BUFFSIZE - 1] = '\0';
  106.  
  107.           p = strchr (vtemp, '<');
  108.           --p;
  109.  
  110.           while (isspace (*p)  &&  p >= vtemp)
  111.                p--;
  112.  
  113.           if (*p == '\"')
  114.                p--;
  115.  
  116.           *(p+1) = '\0';
  117.        }
  118.  
  119.      /* From: EMail_address (real name here) */
  120.      else if ((p = strchr (line, '(')) != NULL)
  121.        {
  122.           strncpy (vtemp, &p[1], BUFFSIZE);
  123.  
  124.           /* be sure string is NULL-terminated */
  125.           vtemp[BUFFSIZE - 1] = '\0';
  126.  
  127.           if ((p = strchr (vtemp, ')')) != NULL)
  128.                *p = '\0';
  129.        }
  130.  
  131.      /* Otherwise, no real name */
  132.      return (vtemp);
  133. }
  134.  
  135.  
  136.  
  137. /* getstring  --get string following the ':' */
  138.  
  139. char *getstring (line)
  140. char *line;
  141. {
  142.      register char *p;
  143.  
  144.      memset (vtemp, '\0', sizeof (vtemp));
  145.  
  146.      if ((p = strchr (line, ':')) != NULL)
  147.        {
  148.           p++;
  149.           p = skipspace (p);
  150.           strncpy (vtemp, p, BUFFSIZE);
  151.  
  152.           /* be sure string is NULL-terminated */
  153.           vtemp[BUFFSIZE - 1] = '\0';
  154.  
  155.           /* eliminate CR */
  156.           if ((p = strchr (vtemp, '\n')) != NULL)
  157.                *p = '\0';
  158.  
  159.           /* eliminate any trailing whitespace */
  160.           p = &vtemp[strlen (vtemp) - 2];
  161.  
  162.           /* hack off any trailing whitespace */
  163.           while (isspace (*p)  &&  p >= vtemp)
  164.             {
  165.                *p = '\0';
  166.                p--;
  167.             }
  168.        }
  169.      return (vtemp);
  170. }
  171.