home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Mail / qpopper-2.4-MIHS / pop_msg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-11  |  2.5 KB  |  98 lines

  1. /*
  2.  * Copyright (c) 1989 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. /*
  8.  * Copyright (c) 1997 by Qualcomm Incorporated.
  9.  */
  10.  
  11. #include <config.h>
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #include <string.h>
  15. #if HAVE_STRINGS_H
  16. #include <strings.h>
  17. #endif
  18. #include <varargs.h>
  19. #include "popper.h"
  20.  
  21. /* 
  22.  *  msg:    Send a formatted line to the POP client
  23.  */
  24.  
  25. pop_msg(va_alist)
  26. va_dcl
  27. {
  28.     POP             *   p;
  29.     int                 stat;               /*  POP status indicator */
  30.     char            *   format;             /*  Format string for the message */
  31.     va_list             ap;
  32.     register char   *   mp;
  33. #ifdef PYRAMID
  34.     char        *   arg1, *arg2, *arg3, *arg4, *arg5, *arg6;
  35. #endif
  36.     char                message[MAXLINELEN];
  37.  
  38.     va_start(ap);
  39.     p = va_arg(ap, POP *);
  40.     stat = va_arg(ap, int);
  41.     format = va_arg(ap, char *);
  42. #ifdef PYRAMID
  43.     arg1 = va_arg(ap, char *);
  44.     arg2 = va_arg(ap, char *);
  45.     arg3 = va_arg(ap, char *);
  46.     arg4 = va_arg(ap, char *);
  47.     arg5 = va_arg(ap, char *);
  48.     arg6 = va_arg(ap, char *);
  49. #endif
  50.  
  51.     /*  Point to the message buffer */
  52.     mp = message;
  53.  
  54.     /*  Format the POP status code at the beginning of the message */
  55.     if (stat == POP_SUCCESS)
  56.         (void)sprintf (mp,"%s ",POP_OK);
  57.     else
  58.         (void)sprintf (mp,"%s ",POP_ERR);
  59.  
  60.     /*  Point past the POP status indicator in the message message */
  61.     mp += strlen(mp);
  62.  
  63.     /*  Append the message (formatted, if necessary) */
  64.     if (format) 
  65. #ifdef HAVE_VPRINTF
  66.         vsprintf(mp,format,ap);
  67. #else
  68. # ifdef PYRAMID
  69.         (void)sprintf(mp,format, arg1, arg2, arg3, arg4, arg5, arg6);
  70. # else
  71.         (void)sprintf(mp,format,((int *)ap)[0],((int *)ap)[1],((int *)ap)[2],
  72.                 ((int *)ap)[3],((int *)ap)[4]);
  73. # endif
  74. #endif
  75.     va_end(ap);
  76.     
  77.     /*  Log the message if debugging is turned on */
  78. #ifdef DEBUG
  79.     if (p->debug && stat == POP_SUCCESS)
  80.         pop_log(p,POP_DEBUG,"%s",message);
  81. #endif
  82.  
  83.     /*  Log the message if a failure occurred */
  84.     if (stat != POP_SUCCESS) 
  85.     pop_log(p,POP_PRIORITY,
  86.                (isdigit (p->client[0]) ? "%s@[%s]: %s" : "%s@%s: %s"),
  87.                (p->user ? p->user : "(null)"), p->client, message);
  88.  
  89.     /*  Append the <CR><LF> */
  90.     (void)strcat(message, "\r\n");
  91.         
  92.     /*  Send the message to the client */
  93.     (void)fputs(message,p->output);
  94.     (void)fflush(p->output);
  95.  
  96.     return(stat);
  97. }
  98.