home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / aix-rs6000 / elm2.3.11.AIX3.1.5.Z / elm2.3.11.AIX3.1.5 / src / bouncebk.c < prev    next >
C/C++ Source or Header  |  1991-11-26  |  3KB  |  116 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: bouncebk.c,v 4.1 90/04/28 22:42:33 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  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:    bouncebk.c,v $
  17.  * Revision 4.1  90/04/28  22:42:33  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  * 
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** This set of routines implement the bounceback feature of the mailer.
  24.     This feature allows mail greater than 'n' hops away (n specified by
  25.     the user) to have a 'cc' to the user through the remote machine.  
  26.  
  27.     Due to the vagaries of the Internet addressing (uucp -> internet -> uucp)
  28.     this will NOT generate bounceback copies with mail to an internet host!
  29.  
  30. **/
  31.  
  32. #include "headers.h"
  33.  
  34. char *bounce_off_remote();        /* forward declaration */
  35.     /* *strcat(), *strcpy(); */
  36.  
  37. int
  38. uucp_hops(to)
  39. char *to;
  40. {    
  41.     /** Given the entire "To:" list, return the number of hops in the
  42.         first address (a hop = a '!') or ZERO iff the address is to a
  43.           non uucp address.
  44.     **/
  45.  
  46.     register int hopcount = 0, iindex;
  47.  
  48.     for (iindex = 0; ! whitespace(to[iindex]) && to[iindex] != '\0'; iindex++) {
  49.       if (to[iindex] == '!')
  50.         hopcount++;
  51.       else if (to[iindex] == '@' || to[iindex] == '%' || to[iindex] == ':')
  52.         return(0);    /* don't continue! */
  53.     }
  54.  
  55.     return(hopcount);
  56. }
  57.     
  58. char *bounce_off_remote(to)
  59. char *to;
  60. {
  61.     /** Return an address suitable for framing (no, that's not it...)
  62.         Er, suitable for including in a 'cc' line so that it ends up
  63.         with the bounceback address.  The method is to take the first 
  64.         address in the To: entry and break it into machines, then 
  65.         build a message up from that.  For example, consider the
  66.         following address:
  67.             a!b!c!d!e!joe
  68.         the bounceback address would be;
  69.             a!b!c!d!e!d!c!b!a!ourmachine!ourname
  70.         simple, eh?
  71.     **/
  72.  
  73.     static char address[LONG_STRING];    /* BEEG address buffer! */
  74.  
  75.     char   host[MAX_HOPS][NLEN];    /* for breaking up addr */
  76.     register int hostcount = 0, hindex = 0, 
  77.            iindex;
  78.  
  79.     for (iindex = 0; !whitespace(to[iindex]) && to[iindex] != '\0'; iindex++) {
  80.       if (to[iindex] == '!') {
  81.         host[hostcount][hindex] = '\0';
  82.         hostcount++;
  83.         hindex = 0;
  84.       }
  85.       else 
  86.         host[hostcount][hindex++] = to[iindex];
  87.     }
  88.  
  89.     /* we have hostcount hosts... */
  90.  
  91.     strcpy(address, host[0]);    /* initialize it! */
  92.  
  93.     for (iindex=1; iindex < hostcount; iindex++) {
  94.       strcat(address, "!");
  95.       strcat(address, host[iindex]);
  96.     }
  97.     
  98.     /* and now the same thing backwards... */
  99.  
  100.     for (iindex = hostcount -2; iindex > -1; iindex--) {
  101.       strcat(address, "!");
  102.       strcat(address, host[iindex]);
  103.     }
  104.  
  105.     /* and finally, let's tack on our machine and login name */
  106.  
  107.     strcat(address, "!");
  108.     strcat(address, hostname);
  109.     strcat(address, "!");
  110.     strcat(address, username);
  111.  
  112.     /* and we're done!! */
  113.  
  114.     return( (char *) address );
  115. }
  116.