home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B25.ZIP / POP.C < prev    next >
Text File  |  1997-04-28  |  35KB  |  1,137 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <fcntl.h>
  6. #include <sys/stat.h>
  7. #include <ctype.h>
  8. #include <mem.h>
  9. #include <conio.h>
  10. #include <io.h>
  11. #include <share.h>
  12. #include <errno.h>
  13. #include <malloc.h>
  14. #include <dir.h>
  15. #include "tcp.h"
  16. #include "pop.h"
  17. #include "version.h"
  18.  
  19. #define POP_PORT 110
  20.  
  21. #define SMTP_PORT 25
  22.  
  23. #define _TEMP_BUFFER_LEN 1024
  24.  
  25. #define SHARE_LEVEL 10
  26. #define WAIT_TIME 10
  27. #define TRIES 100
  28.  
  29. #define MT_DESQVIEW 0x01
  30. #define MT_WINDOWS  0x02
  31. #define MT_OS2      0x04
  32. #define MT_NB       0x40
  33.  
  34.  
  35. #define blankline(LINE) (strspn(LINE, " \n\t\r")==strlen(LINE))
  36.  
  37. #define free_Mail_Socket(SOCK) if (SOCK!=NULL) {     \
  38.   free(SOCK->sock); free(SOCK); SOCK=NULL; }
  39.  
  40. int POP_Err_Cond;
  41. char *POP_Err_Msg = NULL;
  42. static char _POP_err_msg_buf[100] = "";
  43. int SMTP_Err_Cond;
  44. char *SMTP_Err_Msg = NULL;
  45. static char _SMTP_err_msg_buf[100] = "";
  46. char *POPLIB_Err_Msg = NULL;
  47. char from_user[41];
  48. int WatTCP_initialized = 0;
  49. static char _temp_buffer[_TEMP_BUFFER_LEN];
  50. int POP_stat;
  51. int SMTP_stat;
  52. int SOCK_DELAY = 60;
  53. int multitasker = 0;
  54.  
  55. char pktowner[21];
  56.  
  57.  
  58.  
  59. #ifdef SMTP_POP_DEBUG
  60.  
  61. /* ************************************************************************ */
  62.  
  63. #define SOCK_READ_ERR(PROTOCOL)                                                \
  64.   sock_err:                                                                    \
  65.   switch (PROTOCOL##_stat) {                                                   \
  66.     case 1 : /* foreign host closed */                                         \
  67.       sprintf(PROTOCOL##_Err_Msg, #PROTOCOL " Ok");                            \
  68.       sprintf(POPLIB_Err_Msg, "Connection reset: %s.", sockerr(PROTOCOL##_sock->sock)); \
  69.       fprintf(stderr, #PROTOCOL " > %s\n", POPLIB_Err_Msg);                    \
  70.     case -1: /* timeout */                                                     \
  71.       sprintf(PROTOCOL##_Err_Msg, #PROTOCOL " Ok");                            \
  72.       sprintf(POPLIB_Err_Msg, "Timeout: %s.", sockerr(PROTOCOL##_sock->sock)); \
  73.       fprintf(stderr, #PROTOCOL " > %s\n", POPLIB_Err_Msg);                    \
  74.   }
  75.  
  76. #define SOCK_GETS(PROTOCOL) sock_wait_input( PROTOCOL##_sock->sock, SOCK_DELAY, NULL, &PROTOCOL##_stat ); \
  77.   sock_gets( PROTOCOL##_sock->sock, _temp_buffer, sizeof( _temp_buffer ));                                \
  78.   fprintf(stderr, #PROTOCOL"> %s\n", _temp_buffer);                                                       \
  79.   strncpy(PROTOCOL##_Err_Msg, &_temp_buffer[5], 100);
  80.  
  81. #define SMTP_FAIL_ON(NUM, SHUTDOWN)  if ( SMTP_Err_Cond == NUM ) {       \
  82.     fprintf(stderr, "SMTP Failure > '" #NUM "'\n");                      \
  83.     sock_puts( SMTP_sock->sock, "QUIT" );                                \
  84.     sock_close( SMTP_sock->sock );                                       \
  85.     free_Mail_Socket(SMTP_sock);                                         \
  86.     fprintf(stderr, "SMTP Error - '" #NUM "'", 100);         \
  87.     SHUTDOWN;                                                            \
  88.     return(0);                                                           \
  89.   }
  90.  
  91. #define SMTP_FAIL_IF(COND, SHUTDOWN) if ( COND ) {                       \
  92.     fprintf(stderr, "SMTP Failure > (" #COND ")\n");                     \
  93.     sock_puts( SMTP_sock->sock, "QUIT" );                                \
  94.     sock_close( SMTP_sock->sock );                                       \
  95.     free_Mail_Socket(SMTP_sock);                                         \
  96.     fprintf(stderr, "SMTP Error - (" #COND ")", 100);                    \
  97.     SHUTDOWN;                                                            \
  98.     return(0);                                                           \
  99.   }
  100.  
  101. #define SMTP_RESET_ON(NUM, SHUTDOWN) if ( SMTP_Err_Cond == NUM ) {         \
  102.     fprintf(stderr, "SMTP Problem > '" #NUM "'\n");                        \
  103.     sock_puts( SMTP_sock->sock, "RSET" );                                  \
  104.     sock_wait_input( SMTP_sock->sock, SOCK_DELAY, NULL, &SMTP_stat );      \
  105.     sock_gets( SMTP_sock->sock, _temp_buffer, sizeof( _temp_buffer ));     \
  106.     fprintf(stderr, "SMTP Problem - '" #NUM "'", 100);                     \
  107.     SHUTDOWN;                                                              \
  108.     return(0);                                                             \
  109.   }
  110.  
  111. #else
  112.  
  113. /* ************************************************************************ */
  114.  
  115. #define SOCK_READ_ERR(PROTOCOL)                                          \
  116.   sock_err:
  117.  
  118. #define SOCK_GETS(PROTOCOL) sock_wait_input( PROTOCOL##_sock->sock, SOCK_DELAY, NULL, &PROTOCOL##_stat ); \
  119.   sock_gets( PROTOCOL##_sock->sock, _temp_buffer, sizeof( _temp_buffer ));                                \
  120.   strncpy(PROTOCOL##_Err_Msg, &_temp_buffer[5], 100);
  121.  
  122. #define SMTP_FAIL_ON(NUM, SHUTDOWN)  if ( SMTP_Err_Cond == NUM ) {       \
  123.     sock_puts( SMTP_sock->sock, "QUIT" );                                \
  124.     sock_close( SMTP_sock->sock );                                       \
  125.     free_Mail_Socket(SMTP_sock);                                         \
  126.     fprintf(stderr, "SMTP Error - '" #NUM "'", 100);                     \
  127.     SHUTDOWN;                                                            \
  128.     return(0);                                                           \
  129.   }
  130.  
  131. #define SMTP_FAIL_IF(COND, SHUTDOWN) if ( COND ) {                       \
  132.     sock_puts( SMTP_sock->sock, "QUIT" );                                \
  133.     sock_close( SMTP_sock->sock );                                       \
  134.     free_Mail_Socket(SMTP_sock);                                         \
  135.     fprintf(stderr, "SMTP Error - (" #COND ")", 100);                    \
  136.     SHUTDOWN;                                                            \
  137.     return(0);                                                           \
  138.   }
  139.  
  140. #define SMTP_RESET_ON(NUM, SHUTDOWN) if ( SMTP_Err_Cond == NUM ) {         \
  141.     sock_puts( SMTP_sock->sock, "RSET" );                                  \
  142.     sock_wait_input( SMTP_sock->sock, SOCK_DELAY, NULL, &SMTP_stat );      \
  143.     sock_gets( SMTP_sock->sock, _temp_buffer, sizeof( _temp_buffer ));     \
  144.     fprintf(stderr, "SMTP Problem - '" #NUM "'", 100); \
  145.     SHUTDOWN;                                                              \
  146.     return(0);                                                             \
  147.   }
  148.  
  149. #endif
  150.  
  151. /* ************************************************************************ */
  152.  
  153. int get_dos_version(void)
  154. {
  155.   _AX = 0x3000;
  156.   geninterrupt(0x21);
  157.   if (_AX % 256 >= 10) {
  158.     multitasker |= MT_OS2;
  159.   }
  160.   return (_AX);
  161. }
  162.  
  163. int get_dv_version(void)
  164. {
  165.   int v;
  166.  
  167.   if (multitasker & MT_OS2)
  168.     return 0;
  169.   _AX = 0x2b01;
  170.   _CX = 0x4445;
  171.   _DX = 0x5351;
  172.   geninterrupt(0x21);
  173.   if (_AL == 0xff) {
  174.     return 0;
  175.   } else {
  176.     v = _BX;
  177.     multitasker |= MT_DESQVIEW;
  178.     return v;
  179.   }
  180. }
  181.  
  182. int get_win_version(void)
  183. {
  184.   int v = 0;
  185.  
  186.   __emit__(0x55, 0x06, 0x53);
  187.   _AX = 0x352f;
  188.   geninterrupt(0x21);
  189.   _AX = _ES;
  190.   if (_AX | _BX) {
  191.     _AX = 0x1600;
  192.     geninterrupt(0x2f);
  193.     v = _AX;
  194.     if (v % 256 <= 1)
  195.       v = 0;
  196.   }
  197.   __emit__(0x5b, 0x07, 0x5d);
  198.   if (v != 0)
  199.     multitasker |= MT_WINDOWS;
  200.   return (v);
  201. }
  202.  
  203. int get_nb_version(void)
  204. {
  205.   _AX = 0;
  206.   geninterrupt(0x2A);
  207.   return (_AH);
  208. }
  209.  
  210. void detect_multitask(void)
  211. {
  212.   get_dos_version();
  213.   get_win_version();
  214.   get_dv_version();
  215. }
  216.  
  217. unsigned char *trim(char *str)
  218. {
  219.   int i;
  220.  
  221.   if (str == NULL)
  222.     return (str);
  223.   for (i = strlen(str) - 1; (i >= 0) && isspace(str[i]); str[i--] = '\0');
  224.   while (isspace(str[0]))
  225.     strcpy(str, str + 1);
  226.   return (str);
  227. }
  228.  
  229. unsigned char *strrep(char *str, char old, char New)
  230. {
  231.   int i;
  232.  
  233.   for (i = 0; str[i]; i++)
  234.     if (str[i] == old)
  235.       str[i] = New;
  236.   return (str);
  237. }
  238.  
  239. int getnumbers(unsigned char *ascii, unsigned int *d1, unsigned long *d2)
  240. {
  241.   char *p;
  242.  
  243.   /* it must return a number after the white space */
  244.   if ((p = (char *) _fstrchr((char *) ascii, ' ')) == NULL)
  245.     return 0;
  246.   /* skip space */
  247.   while (*p == ' ')
  248.     p++;
  249.   *d1 = atoi(p);
  250.   if ((p = (char *) _fstrchr(p, ' ')) == NULL)
  251.     return 1;
  252.   /* skip space */
  253.   while (*p == ' ')
  254.     p++;
  255.   *d2 = atol(p);
  256.   return 2;
  257. }
  258.  
  259. char *fix_quoted_commas(char *string)
  260. {
  261.   char *ptr;
  262.   int quoted = 0;
  263.  
  264.   ptr = string;
  265.   if (ptr) {
  266.     while (*ptr != 0) {
  267.       if (*ptr == '\"')
  268.         quoted = (!quoted);
  269.       if (*ptr == ',' && quoted)
  270.         *ptr = '│';
  271.       ptr = &ptr[1];
  272.     }
  273.   }
  274.   return (string);
  275. }
  276.  
  277. long sh_lseek(int handle, long offset, int fromwhere)
  278. {
  279.   if (handle == -1) {
  280.     return (-1L);
  281.   }
  282.   return (lseek(handle, offset, fromwhere));
  283. }
  284.  
  285. FILE *fsh_open(char *path, char *fmode)
  286. {
  287.   FILE *f;
  288.   int count, share, md, fd;
  289.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  290.  
  291.   share = SH_DENYWR;
  292.   md = 0;
  293.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  294.     share = SH_DENYRD;
  295.     md = O_RDWR | O_CREAT | O_TRUNC;
  296.   } else
  297.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  298.     share = SH_DENYRD;
  299.     md = O_RDWR | O_CREAT;
  300.   } else {
  301.     md = O_RDONLY;
  302.   }
  303.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  304.     md |= O_BINARY;
  305.   }
  306.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  307.     md &= ~O_RDONLY;
  308.     md |= O_RDWR;
  309.     share = SH_DENYRD;
  310.   }
  311.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  312.   if (fd < 0) {
  313.     count = 1;
  314.     fnsplit(path, drive, dir, file, ext);
  315.     if ((access(path, 0)) != -1) {
  316.       delay(WAIT_TIME);
  317.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  318.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  319.         delay(WAIT_TIME);
  320.         count++;
  321.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  322.       }
  323.     }
  324.   }
  325.   if (fd > 0) {
  326.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  327.       sh_lseek(fd, 0L, SEEK_END);
  328.     f = fdopen(fd, fmode);
  329.     if (!f) {
  330.       close(fd);
  331.     }
  332.   } else
  333.     f = 0;
  334.   return (f);
  335. }
  336.  
  337. Mail_Socket *smtp_start(char *host, char *dom)
  338. {
  339.   longword h;
  340.   Mail_Socket *SMTP_sock = NULL;
  341.  
  342.   if (!SMTP_Err_Msg)
  343.     SMTP_Err_Msg = _SMTP_err_msg_buf;
  344.   if (!WatTCP_initialized) {
  345.     sock_init();
  346.     WatTCP_initialized = 1;
  347.   }
  348.   if (!(h = resolve(host))) {
  349.     SMTP_Err_Cond = SMTP_FAILED;
  350. #ifdef SMTP_POP_DEBUG
  351.     sprintf(SMTP_Err_Msg, "Cannot resolve host %s", host);
  352.     fprintf(stderr, "\nSMTP> %s", SMTP_Err_Msg);
  353. #endif
  354.     return NULL;
  355.   }
  356.   if ((SMTP_sock = (Mail_Socket *) malloc(sizeof(Mail_Socket))) == NULL) {
  357.     fprintf(stderr, "\n ■ Insufficient memory to create socket... aborting");
  358.     exit(EXIT_FAILURE);
  359.   }
  360.   if ((SMTP_sock->sock = (tcp_Socket *) malloc(sizeof(tcp_Socket))) == NULL) {
  361.     fprintf(stderr, "\n ■ Insufficient memory to create socket... aborting");
  362.     free(SMTP_sock);
  363.     exit(EXIT_FAILURE);
  364.   }
  365.   if (!tcp_open(SMTP_sock->sock, 0, h, SMTP_PORT, NULL)) {
  366.     SMTP_Err_Cond = SMTP_FAILED;
  367. #ifdef SMTP_POP_DEBUG
  368.     sprintf(SMTP_Err_Msg, "Unable to connect to %s", host);
  369.     fprintf(stderr, "\nSMTP> %s", SMTP_Err_Msg);
  370. #endif
  371.     free(SMTP_sock);
  372.     return NULL;
  373.   }
  374.   sock_mode(SMTP_sock->sock, TCP_MODE_ASCII);
  375.   sock_wait_established(SMTP_sock->sock, SOCK_DELAY, NULL, &SMTP_stat);
  376.   while (sock_tbused(SMTP_sock->sock) > 0) {
  377.     SOCK_GETS(SMTP);
  378.     SMTP_FAIL_ON(SMTP_OOPS,);
  379.   }
  380.   sock_printf(SMTP_sock->sock, "HELO %s", dom);
  381.   sock_wait_input(SMTP_sock->sock, SOCK_DELAY, NULL, &SMTP_stat);
  382.   while (sock_tbused(SMTP_sock->sock) > 0) {
  383.     SOCK_GETS(SMTP);
  384.     SMTP_FAIL_ON(SMTP_OOPS,);
  385.     SMTP_FAIL_ON(SMTP_SYNTAX,);
  386.     SMTP_FAIL_ON(SMTP_PARAM,);
  387.     SMTP_FAIL_ON(SMTP_BAD_PARM,);
  388.   }
  389.   return (SMTP_sock);
  390.   SOCK_READ_ERR(SMTP);
  391.   return NULL;
  392. }
  393.  
  394. char *smtp_parse_from_line(FILE * f)
  395. {
  396.   int found = 0, done = 0;
  397.  
  398.   rewind(f);
  399.   while (!feof(f) && !done) {
  400.     fgets(_temp_buffer, sizeof(_temp_buffer), f);
  401.     if (*_temp_buffer == '\n')
  402.       done = 1;
  403.     else
  404.       if (strncmpi(_temp_buffer, "from:", 5) == 0 &&
  405.           _fstrchr(_temp_buffer, '@') != 0)
  406.       found = 1, done = 1;
  407.   }
  408.   if (found)
  409.     return (trim(strdup(&_temp_buffer[5])));
  410.   return 0;
  411. }
  412.  
  413. char **smtp_parse_to_line(FILE * f)
  414. {
  415.   int done = 0, current = 0;
  416.   char **list = NULL;
  417.   char *addr;
  418.  
  419.   rewind(f);
  420.   while (!feof(f) && !done) {
  421.     fgets(_temp_buffer, sizeof(_temp_buffer), f);
  422.     if (*_temp_buffer == '\n')
  423.       done = 1;
  424.     else
  425.       if ((strncmpi(_temp_buffer, "to:", 3) == 0) ||
  426.           (strncmpi(_temp_buffer, "cc:", 3) == 0) ||
  427.           (strncmpi(_temp_buffer, "bcc:", 4) == 0)) {
  428.       fix_quoted_commas(_temp_buffer);
  429.       addr = strtok(_temp_buffer, ":");
  430.       while ((addr = strtok(NULL, ",\n")) != NULL) {
  431.         strrep(addr, '│', ',');
  432.         list = (char **) realloc(list, sizeof(char *) * ((current) + 2));
  433.         list[current] = strdup(addr);
  434.         list[current + 1] = NULL;
  435.         current++;
  436.       }
  437.       }
  438.   }
  439.   return (list);
  440. }
  441.  
  442. int smtp_send_MAIL_FROM_line(Mail_Socket * SMTP_sock, FILE * f)
  443. {
  444.   char *from;
  445.  
  446.   from = smtp_parse_from_line(f);
  447.   if (from) {
  448. #ifdef SMTP_POP_DEBUG
  449.     fprintf(stderr, "\nFrom: %s", from);
  450. #endif
  451.     sock_printf(SMTP_sock->sock, "MAIL FROM:<%s>", from);
  452.     free(from);
  453.     while (sock_tbused(SMTP_sock->sock) > 0) {
  454.       SOCK_GETS(SMTP);
  455.       SMTP_FAIL_ON(SMTP_OOPS,);
  456.     }
  457.   }
  458.   return 1;
  459.   SOCK_READ_ERR(SMTP);
  460.   return 0;
  461. }
  462.  
  463. #define FREE_ALL for (i=0; to_list[i]!=NULL; i++) if (to_list[i]) free(to_list[i]); if (to_list) free(to_list);
  464.  
  465. int smtp_send_RCPT_TO_line(Mail_Socket * SMTP_sock, FILE * f)
  466. {
  467.   char **to_list;
  468.   int i;
  469.  
  470.   to_list = smtp_parse_to_line(f);
  471.   for (i = 0; to_list[i] != NULL; i++) {
  472. #ifdef SMTP_POP_DEBUG
  473.     fprintf(stderr, "\nTo: %s", to_list[i]);
  474. #endif
  475.     sock_printf(SMTP_sock->sock, "RCPT TO:<%s>", to_list[i]);
  476.     while (sock_tbused(SMTP_sock->sock) > 0) {
  477.       SOCK_GETS(SMTP);
  478.       SMTP_FAIL_ON(SMTP_OOPS, FREE_ALL);
  479.       SMTP_RESET_ON(SMTP_SYNTAX, FREE_ALL);
  480.       SMTP_RESET_ON(SMTP_PARAM, FREE_ALL);
  481.       SMTP_RESET_ON(SMTP_BAD_SEQ, FREE_ALL);
  482.     }
  483.   }
  484.   FREE_ALL;
  485.   return 1;
  486.   SOCK_READ_ERR(SMTP);
  487.   return 0;
  488. }
  489.  
  490. #undef FREE_ALL
  491.  
  492. int smtp_sendf(Mail_Socket * SMTP_sock, FILE * f)
  493. {
  494.   int in_header = 1, in_bcc = 0, i, pos;
  495.   long nbytes, obytes, rbytes;
  496.   char *temp;
  497.  
  498.   if (smtp_send_MAIL_FROM_line(SMTP_sock, f) == 0)
  499.     return 0;
  500.   if (smtp_send_RCPT_TO_line(SMTP_sock, f) == 0)
  501.     return 0;
  502.   fseek(f, 0L, SEEK_END);
  503.   obytes = ftell(f);
  504.   rewind(f);
  505.   sock_puts(SMTP_sock->sock, "DATA");
  506.   sock_wait_input(SMTP_sock->sock, SOCK_DELAY, NULL, &SMTP_stat);
  507.   while (sock_tbused(SMTP_sock->sock) > 0) {
  508.     SOCK_GETS(SMTP);
  509. #ifdef SMTP_POP_DEBUG
  510.     fprintf(stderr, "\nSMTP> %s", _temp_buffer);
  511. #endif
  512.     SMTP_FAIL_ON(SMTP_OOPS,);
  513.     SMTP_RESET_ON(SMTP_SYNTAX,);
  514.     SMTP_RESET_ON(SMTP_PARAM,);
  515.     SMTP_RESET_ON(SMTP_COM_NI,);
  516.     SMTP_RESET_ON(SMTP_FAILED,);
  517.     SMTP_RESET_ON(SMTP_ERROR,);
  518.   }
  519.   nbytes = 0L;
  520.   rbytes = 1024L;
  521.   fprintf(stderr, " - ");
  522.   pos = wherex();
  523.   while (!feof(f)) {
  524.     fgets(_temp_buffer, sizeof(_temp_buffer), f);
  525.     strrep(_temp_buffer, '\n', '\0');
  526.     strrep(_temp_buffer, '\r', '\0');
  527.     temp = trim(strdup(_temp_buffer));
  528.     if (strlen(temp) == 0)
  529.       in_header = 0;
  530.     if (temp)
  531.       free(temp);
  532.     if (in_header && !in_bcc && strncmpi(_temp_buffer, "bcc:", 4) == 0) {
  533.       in_bcc = 1;
  534.       continue;
  535.     }
  536.     if (in_bcc)
  537.       in_bcc = isspace(*_temp_buffer);
  538.     if (in_bcc)
  539.       continue;
  540.     if (*_temp_buffer == '.') {
  541.       movmem(_temp_buffer, _temp_buffer + 1, sizeof(_temp_buffer) - 1);
  542.       *_temp_buffer = '.';
  543. #ifdef SMTP_POP_DEBUG
  544.       fprintf(stderr, "\nSMTP> %s", _temp_buffer);
  545. #endif
  546.     }
  547.     nbytes += sock_puts(SMTP_sock->sock, _temp_buffer);
  548.     nbytes += 2;
  549.     if (nbytes > rbytes) {
  550.       for (i = wherex(); i > pos; i--)
  551.         fprintf(stderr, "\b");
  552.       fprintf(stderr, "%ld of %ld bytes", nbytes, obytes);
  553.       rbytes += 512L;
  554.     }
  555.   }
  556.   sock_puts(SMTP_sock->sock, ".");
  557.   sock_wait_input(SMTP_sock->sock, SOCK_DELAY, NULL, &SMTP_stat);
  558.   while (sock_tbused(SMTP_sock->sock) > 0) {
  559.     SOCK_GETS(SMTP);
  560.     SMTP_FAIL_ON(SMTP_OOPS,);
  561.     SMTP_RESET_ON(SMTP_ERROR,);
  562.     SMTP_RESET_ON(SMTP_SQUEEZED,);
  563.     SMTP_RESET_ON(SMTP_FULL,);
  564.     SMTP_RESET_ON(SMTP_FAILED,);
  565.   }
  566.   for (i = wherex(); i > pos; i--)
  567.     fprintf(stderr, "\b \b");
  568.   fprintf(stderr, "message sent!");
  569.   return 1;
  570.   SOCK_READ_ERR(SMTP);
  571.   return 0;
  572. }
  573.  
  574. int smtp_shutdown(Mail_Socket * SMTP_sock)
  575. {
  576.   if (SMTP_sock->sock) {
  577.     sock_puts(SMTP_sock->sock, "QUIT");
  578.     sock_close(SMTP_sock->sock);
  579.     return 1;
  580.   }
  581. sock_err:
  582.   free_Mail_Socket(SMTP_sock);
  583.   return 0;
  584. }
  585.  
  586.  
  587. Mail_Socket *pop_init(char *host)
  588. {
  589.   longword h;
  590.   Mail_Socket *POP_sock = NULL;
  591.  
  592.   if (!POP_Err_Msg)
  593.     POP_Err_Msg = _POP_err_msg_buf;
  594.  
  595.   if (!WatTCP_initialized) {
  596.     sock_init();
  597.     WatTCP_initialized = 1;
  598.   }
  599.   if (!(h = resolve(host))) {
  600.     fprintf(stderr, "\n ■ Cannot resolve host %s.", host);
  601.     POP_Err_Cond = POP_BAD_HOST;
  602. #ifdef SMTP_POP_DEBUG
  603.     sprintf(POP_Err_Msg, "Cannot resolve host %s", host);
  604.     fprintf(stderr, "\n%s", POP_Err_Msg);
  605. #endif
  606.     return NULL;
  607.   }
  608.   if ((POP_sock = (Mail_Socket *) malloc(sizeof(Mail_Socket))) == NULL) {
  609.     fprintf(stderr, "\n ■ Insufficient memory to create socket... aborting.");
  610.     exit(EXIT_FAILURE);
  611.   }
  612.   if ((POP_sock->sock = (tcp_Socket *) malloc(sizeof(tcp_Socket))) == NULL) {
  613.     fprintf(stderr, "\n ■ Insufficient memory to create socket... aborting.");
  614.     free(POP_sock);
  615.     exit(EXIT_FAILURE);
  616.   }
  617.   if (!tcp_open(POP_sock->sock, 0, h, POP_PORT, NULL)) {
  618.     fprintf(stderr, "\n ■ Unable to connect to host %s.", host);
  619.     POP_Err_Cond = POP_BAD_HOST;
  620. #ifdef SMTP_POP_DEBUG
  621.     sprintf(POP_Err_Msg, "Unable to connect to host %s", host);
  622.     fprintf(stderr, "\n%s", POP_Err_Msg);
  623. #endif
  624.     return NULL;
  625.   }
  626.   sock_mode(POP_sock->sock, TCP_MODE_ASCII);
  627.   sock_wait_established(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  628.   sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  629.   sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  630. #ifdef SMTP_POP_DEBUG
  631.   fprintf(stderr, "\nPOP> %s", _temp_buffer);
  632. #endif
  633.   if (*_temp_buffer != '+') {
  634.     fprintf(stderr, "\n ■ Host %s is unavailable.", host);
  635.     POP_Err_Cond = POP_HOST_UNAVAILABLE;
  636. #ifdef SMTP_POP_DEBUG
  637.     sprintf(POP_Err_Msg, "Host %s unavailable", host);
  638. #endif
  639.     if (POP_sock->sock) {
  640.       sock_puts(POP_sock->sock, "QUIT");
  641.       sock_close(POP_sock->sock);
  642.     }
  643.     return NULL;
  644.   }
  645.   return (POP_sock);
  646.   SOCK_READ_ERR(POP);
  647.   return NULL;
  648. }
  649.  
  650. int pop_login(Mail_Socket * POP_sock, char *userid, char *password)
  651. {
  652.   sprintf(_temp_buffer, "USER %s", userid);
  653.   sock_puts(POP_sock->sock, _temp_buffer);
  654.   sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  655.   sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  656. #ifdef SMTP_POP_DEBUG
  657.   fprintf(stderr, "\nPOP> %s", _temp_buffer);
  658. #endif
  659.   if (*_temp_buffer != '+') {
  660.     fprintf(stderr, "\n ■ Host reports mailbox \"%s\" does not exist!", userid);
  661.     POP_Err_Cond = POP_BAD_MBOX;
  662. #ifdef SMTP_POP_DEBUG
  663.     sprintf(POP_Err_Msg, "Mailbox %s does not exist", userid);
  664. #endif
  665.     return 0;
  666.   }
  667.   sprintf(_temp_buffer, "PASS %s", password);
  668.   sock_puts(POP_sock->sock, _temp_buffer);
  669.   sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  670.   sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  671. #ifdef SMTP_POP_DEBUG
  672.   fprintf(stderr, "\nPOP> %s", _temp_buffer);
  673. #endif
  674.   if (*_temp_buffer != '+') {
  675.     fprintf(stderr, "\n ■ Host reports \"%s\" is incorrect password or account is locked.", password);
  676.     POP_Err_Cond = POP_BAD_PASS;
  677. #ifdef SMTP_POP_DEBUG
  678.     sprintf(POP_Err_Msg, "Password incorrect");
  679. #endif
  680.     return 0;
  681.   }
  682.   return 1;
  683.   SOCK_READ_ERR(POP);
  684.   return 0;
  685. }
  686.  
  687. int pop_status(Mail_Socket * POP_sock, unsigned int *count, unsigned long *totallength)
  688. {
  689.   sock_puts(POP_sock->sock, "STAT");
  690.   sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  691.   sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  692. #ifdef SMTP_POP_DEBUG
  693.   fprintf(stderr, "\nPOP> %s", _temp_buffer);
  694. #endif
  695.   if ((*_temp_buffer != '+') ||
  696.       (getnumbers(_temp_buffer, count, totallength) < 2)) {
  697.     POP_Err_Cond = POP_UNKNOWN;
  698. #ifdef SMTP_POP_DEBUG
  699.     sprintf(POP_Err_Msg, "Unknown POP error");
  700.     fprintf(stderr, "\n%s", POP_Err_Msg);
  701. #endif
  702.     return 0;
  703.   }
  704.   return 1;
  705.   SOCK_READ_ERR(POP);
  706.   return 0;
  707. }
  708.  
  709. long pop_length(Mail_Socket * POP_sock, unsigned int msg_num, unsigned long *size)
  710. {
  711.   unsigned int dummy;
  712.  
  713.   sprintf(_temp_buffer, "LIST %u", msg_num);
  714.   sock_puts(POP_sock->sock, _temp_buffer);
  715.   sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  716.   sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  717. #ifdef SMTP_POP_DEBUG
  718.   fprintf(stderr, "\nPOP> %s", _temp_buffer);
  719. #endif
  720.   if ((*_temp_buffer != '+') ||
  721.       (getnumbers(_temp_buffer, &dummy, size) < 2)) {
  722.     POP_Err_Cond = POP_NOT_MSG;
  723. #ifdef SMTP_POP_DEBUG
  724.     sprintf(POP_Err_Msg, "No message #%u", msg_num);
  725.     fprintf(stderr, "\n%s", POP_Err_Msg);
  726. #endif
  727.     return 0;
  728.   }
  729.   return (*size);
  730.   SOCK_READ_ERR(POP);
  731.   return 0;
  732. }
  733.  
  734. char *stristr(char *String, char *Pattern)
  735. {
  736.   char *pptr, *sptr, *start;
  737.   unsigned int slen, plen;
  738.  
  739.   for (start = String, pptr = Pattern, slen = strlen(String),
  740.        plen = strlen(Pattern); slen >= plen; start++, slen--) {
  741.     while (toupper(*start) != toupper(*Pattern)) {
  742.       start++;
  743.       slen--;
  744.       if (slen < plen)
  745.         return (NULL);
  746.     }
  747.     sptr = start;
  748.     pptr = Pattern;
  749.     while (toupper(*sptr) == toupper(*pptr)) {
  750.       sptr++;
  751.       pptr++;
  752.       if ('\0' == *pptr)
  753.         return (start);
  754.     }
  755.   }
  756.   return (NULL);
  757. }
  758.  
  759. int pop_top(Mail_Socket * POP_sock, unsigned int msg_num)
  760. {
  761.   int okpkt;
  762.  
  763.   sprintf(_temp_buffer, "TOP %u 50", msg_num);
  764. /*  sock_printf(POP_sock->sock, "TOP %u 50\n", msg_num); */
  765.   sock_puts(POP_sock->sock, _temp_buffer);
  766.   sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  767.   sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  768. #ifdef SMTP_POP_DEBUG
  769.   fprintf(stderr, "\nPOP> %s", _temp_buffer);
  770. #endif
  771.   if (*_temp_buffer != '+') {
  772.     POP_Err_Cond = POP_NOT_MSG;
  773. #ifdef SMTP_POP_DEBUG
  774.     sprintf(POP_Err_Msg, "No message #%ld.", msg_num);
  775.     fprintf(stderr, "\n%s", POP_Err_Msg);
  776. #endif
  777.     return -1;
  778.   }
  779.   okpkt = 0;
  780.   while (1) {
  781.     sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  782.     sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  783.     if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0)
  784.       break;
  785.     if (strnicmp(_temp_buffer, "begin ", 6) == 0) {
  786.       if (okpkt != 4)
  787.         okpkt = 1;
  788.       if ((stristr(_temp_buffer, ".ZIP") != NULL) ||
  789.           (stristr(_temp_buffer, ".ARJ") != NULL) ||
  790.           (stristr(_temp_buffer, ".LZH") != NULL))
  791.         okpkt = 2;
  792.       if ((stristr(_temp_buffer, ".GIF") != NULL) ||
  793.           (stristr(_temp_buffer, ".JPG") != NULL))
  794.         okpkt = 3;
  795.     }
  796.     if (strnicmp(_temp_buffer, "from:", 5) == 0) {
  797.       if ((stristr(_temp_buffer, "mailer-daemon") != NULL) ||
  798.           (stristr(_temp_buffer, "mail delivery") != NULL) ||
  799.           (stristr(_temp_buffer, "administrator") != NULL) ||
  800.           (stristr(_temp_buffer, from_user) != NULL))
  801.         okpkt = 4;
  802.       else
  803.         strncpy(pktowner, &_temp_buffer[6], 20);
  804.     }
  805.   }
  806.   return okpkt;
  807.   SOCK_READ_ERR(POP);
  808.   return -1;
  809. }
  810.  
  811. int pop_getf(Mail_Socket * POP_sock, char *fn, unsigned int msg_num)
  812. {
  813.   unsigned long size;
  814.   long nbytes, rbytes;
  815.   int i, pos, ctld;
  816.   FILE *fp;
  817.  
  818.   if (!pop_length(POP_sock, msg_num, &size)) {
  819.     fprintf(stderr, "\n ■ Unable to retrieve message number %d", msg_num);
  820.     return 0;
  821.   }
  822.   sprintf(_temp_buffer, "RETR %u", msg_num);
  823.   sock_puts(POP_sock->sock, _temp_buffer);
  824.   sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  825.   sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  826. #ifdef SMTP_POP_DEBUG
  827.   fprintf(stderr, "\nPOP> %s", _temp_buffer);
  828. #endif
  829.   if (*_temp_buffer != '+') {
  830.     POP_Err_Cond = POP_NOT_MSG;
  831. #ifdef SMTP_POP_DEBUG
  832.     sprintf(POP_Err_Msg, "No message #%u", msg_num);
  833.     fprintf(stderr, "\n%s", POP_Err_Msg);
  834. #endif
  835.     return 0;
  836.   }
  837.   nbytes = 0L;
  838.   rbytes = 1024L;
  839.   fprintf(stderr, " - ");
  840.   pos = wherex();
  841.   if ((fp = fsh_open(fn, "w")) == NULL) {
  842.     fprintf(stderr, "\n ■ Unable to create %s... aborting!", fn);
  843.     return 0;
  844.   }
  845.   ctld = 1;
  846.   while (1) {
  847.     sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  848.     sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  849.     if ((*_temp_buffer == '\r') || (*_temp_buffer == '\n') || (*_temp_buffer == 0))
  850.       ctld = 0;
  851.     if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0)
  852.       break;
  853.     if (EOF == (nbytes += fprintf(fp, "%s%s\n", ctld ? "0R" : "", _temp_buffer))) {
  854.       fclose(fp);
  855.       return 0;
  856.     }
  857.     if (nbytes > rbytes) {
  858.       for (i = wherex(); i > pos; i--)
  859.         fprintf(stderr, "\b");
  860.       fprintf(stderr, "%ld of %ld bytes", nbytes, size);
  861.       rbytes += 512L;
  862.     }
  863.   }
  864.   if (fp)
  865.     fclose(fp);
  866.   for (i = wherex(); i > pos; i--)
  867.     fprintf(stderr, "\b \b");
  868.   fprintf(stderr, "message received!");
  869.   return 1;
  870.   SOCK_READ_ERR(POP);
  871.   return 0;
  872. }
  873.  
  874. int pop_delete(Mail_Socket * POP_sock, unsigned int msg_num)
  875. {
  876.   sprintf(_temp_buffer, "DELE %u", msg_num);
  877.   sock_puts(POP_sock->sock, _temp_buffer);
  878.   sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  879.   sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  880. #ifdef SMTP_POP_DEBUG
  881.   fprintf(stderr, "\nPOP> %s", _temp_buffer);
  882. #endif
  883.   if (*_temp_buffer != '+') {
  884.     POP_Err_Cond = POP_NOT_MSG;
  885. #ifdef SMTP_POP_DEBUG
  886.     sprintf(POP_Err_Msg, "No message #%u", msg_num);
  887.     fprintf(stderr, "\n%s", POP_Err_Msg);
  888. #endif
  889.     return 2;
  890.   }
  891.   return 1;
  892.   SOCK_READ_ERR(POP);
  893.   return 0;
  894. }
  895.  
  896.  
  897. int pop_shutdown(Mail_Socket * POP_sock)
  898. {
  899.   if (POP_sock->sock) {
  900.     sock_puts(POP_sock->sock, "QUIT");
  901.     sock_wait_input(POP_sock->sock, SOCK_DELAY, NULL, &POP_stat);
  902.     sock_gets(POP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  903.     if (*_temp_buffer != '+') {
  904.       POP_Err_Cond = POP_UNKNOWN;
  905. #ifdef SMTP_POP_DEBUG
  906.       sprintf(POP_Err_Msg, "Unable to update mailbox!");
  907.       fprintf(stderr, "\n%s", POP_Err_Msg);
  908. #endif
  909.       return 0;
  910.     } else
  911.       fprintf(stderr, "\n ■ Successfully closed and updated mailbox");
  912.     sock_close(POP_sock->sock);
  913.     return 1;
  914.   }
  915. sock_err:
  916.   free_Mail_Socket(POP_sock);
  917.   return 0;
  918. }
  919.  
  920. int pop_get_nextf(Mail_Socket * POP_sock, char *fn, int msgnum)
  921. {
  922.   if (!pop_getf(POP_sock, fn, msgnum))
  923.     return 0;
  924.   return (pop_delete(POP_sock, msgnum));
  925. }
  926.  
  927. int exist(char *s)
  928. {
  929.   int i;
  930.   struct ffblk ff;
  931.  
  932.   i = findfirst(s, &ff, FA_HIDDEN);
  933.   if (i)
  934.     return 0;
  935.   else
  936.     return 1;
  937. }
  938.  
  939. void main(int argc, char *argv[])
  940. {
  941.   unsigned int count;
  942.   unsigned long size;
  943.   int i, i1, okpkt;
  944.   char temp[181], s[21], s1[21];
  945.   FILE *fp;
  946.   Mail_Socket *pop_sock = NULL;
  947.   Mail_Socket *smtp_sock = NULL;
  948.  
  949.   if (get_nb_version())
  950.     multitasker = 8;
  951.   else
  952.     detect_multitask();
  953.   switch (multitasker) {
  954.     case 1:
  955.       get_dv_version();
  956.       break;
  957.     case 2:
  958.       get_win_version();
  959.       break;
  960.     case 3:
  961.       get_dv_version();
  962.       break;
  963.     case 4:
  964.     case 5:
  965.     case 6:
  966.     case 7:
  967.       break;
  968.     case 8:
  969.       multitasker = 1;
  970.       break;
  971.     default:
  972.       break;
  973.   }
  974.  
  975.   if (strncmpi(argv[1], "-send", strlen(argv[1])) == 0) {
  976.     if (argc != 5)
  977.       exit(EXIT_FAILURE);
  978.     fprintf(stderr, "via %s", argv[2]);
  979.     if ((smtp_sock = smtp_start(argv[2], argv[3])) != NULL) {
  980.       if ((fp = fsh_open(argv[4], "r")) != NULL) {
  981.         if (smtp_sendf(smtp_sock, fp)) {
  982.           smtp_shutdown(smtp_sock);
  983.           fclose(fp);
  984.           exit(EXIT_SUCCESS);
  985.         } else {
  986.           smtp_shutdown(smtp_sock);
  987.           fprintf(stderr, "\n ■ SMTP socket failure during send.");
  988.           fclose(fp);
  989.         }
  990.       } else {
  991.         smtp_shutdown(smtp_sock);
  992.         fprintf(stderr, "\n ■ Error accessing file %s.", argv[4]);
  993.       }
  994.     } else
  995.       fprintf(stderr, "\n ■ SMTP socket connect failed.");
  996.   } else
  997.     if (strncmpi(argv[1], "-receive", strlen(argv[1])) == 0) {
  998.     if (argc != 8) {
  999.       fprintf(stderr, "Received: ");
  1000.       for (i = 0; i < argc; i++)
  1001.         fprintf(stderr, "%s ", argv[i]);
  1002.       exit(EXIT_FAILURE);
  1003.     }
  1004.     sprintf(from_user, "%s@%s", argv[3], argv[7]);
  1005.     if ((pop_sock = pop_init(argv[2])) != NULL) {
  1006.       if (pop_login(pop_sock, argv[3], argv[4])) {
  1007.         if (pop_status(pop_sock, &count, &size)) {
  1008.           okpkt = 0;
  1009.           fprintf(stderr, "\n ■ Account \"%s\" has %u message%s, %lu bytes total.",
  1010.                   argv[3], count, count == 1 ? "" : "s", size);
  1011.           i1 = 1;
  1012.           while (i1 <= count) {
  1013.             okpkt = -1;
  1014.             okpkt = pop_top(pop_sock, i1);
  1015.             switch (okpkt) {
  1016.               case -1:
  1017.                 fprintf(stderr, "\n ■ Error accessing message %d", i1);
  1018.                 break;
  1019.               case 0:
  1020.                 i = atoi(argv[6]);
  1021.                 if (i == 0)
  1022.                   fprintf(stderr, "\n ■ Non-network message %d left on server.", i1);
  1023.                 else {
  1024.                   i = 0;
  1025.                   sprintf(temp, "%sUNK-%03d.MSG", argv[5], i);
  1026.                   while (exist(temp))
  1027.                     sprintf(temp, "%sUNK-%03d.MSG", argv[5], ++i);
  1028.                   fnsplit(temp, NULL, NULL, s, s1);
  1029.                   fprintf(stderr, "\n ■ Message %3.3d - %-20s - %s%s", i1, "non-network packet", s, s1);
  1030.                   switch (pop_get_nextf(pop_sock, temp, i1)) {
  1031.                     case 0:
  1032.                       fprintf(stderr, "\n ■ Unable to retrieve message %d.", i1);
  1033.                       unlink(temp);
  1034.                       break;
  1035.                     case 1:
  1036.                       break;
  1037.                     case 2:
  1038.                       fprintf(stderr, "\n ■ Unable to delete message %d from host!", i1);
  1039.                       break;
  1040.                   }
  1041.                 }
  1042.                 break;
  1043.               case 1:
  1044.                 i = 0;
  1045.                 sprintf(temp, "%sPKT-%03d.UUE", argv[5], i);
  1046.                 while (exist(temp))
  1047.                   sprintf(temp, "%sPKT-%03d.UUE", argv[5], ++i);
  1048.                 fnsplit(temp, NULL, NULL, s, s1);
  1049.                 fprintf(stderr, "\n ■ Message %3.3d - %-20s - %s%s", i1, pktowner, s, s1);
  1050.                 switch (pop_get_nextf(pop_sock, temp, i1)) {
  1051.                   case 0:
  1052.                     fprintf(stderr, "\n ■ Unable to retrieve message %d.", i1);
  1053.                     unlink(temp);
  1054.                     break;
  1055.                   case 1:
  1056.                     break;
  1057.                   case 2:
  1058.                     fprintf(stderr, "\n ■ Unable to delete message %d on host!", i1);
  1059.                     break;
  1060.                 }
  1061.                 break;
  1062.               case 2:
  1063.                 i = 0;
  1064.                 sprintf(temp, "%sARC-%03d.UUE", argv[5], i);
  1065.                 while (exist(temp))
  1066.                   sprintf(temp, "%sARC-%03d.UUE", argv[5], ++i);
  1067.                 fnsplit(temp, NULL, NULL, s, s1);
  1068.                 fprintf(stderr, "\n ■ Message %3.3d - %-20s - %s%s", i1, "archived file", s, s1);
  1069.                 switch (pop_get_nextf(pop_sock, temp, i1)) {
  1070.                   case 0:
  1071.                     fprintf(stderr, "\n ■ Unable to retrieve message %d.", i1);
  1072.                     unlink(temp);
  1073.                     break;
  1074.                   case 1:
  1075.                     break;
  1076.                   case 2:
  1077.                     fprintf(stderr, "\n ■ Unable to delete message %d on host!", i1);
  1078.                     break;
  1079.                 }
  1080.                 break;
  1081.               case 3:
  1082.                 i = 0;
  1083.                 sprintf(temp, "%sGIF-%03d.UUE", argv[5], i);
  1084.                 while (exist(temp))
  1085.                   sprintf(temp, "%sGIF-%03d.UUE", argv[5], ++i);
  1086.                 fnsplit(temp, NULL, NULL, s, s1);
  1087.                 fprintf(stderr, "\n ■ Message %3.3d - %-20s - %s%s", i1, "graphic/image file", s, s1);
  1088.                 switch (pop_get_nextf(pop_sock, temp, i1)) {
  1089.                   case 0:
  1090.                     fprintf(stderr, "\n ■ Unable to retrieve message %d.", i1);
  1091.                     unlink(temp);
  1092.                     break;
  1093.                   case 1:
  1094.                     break;
  1095.                   case 2:
  1096.                     fprintf(stderr, "\n ■ Unable to delete message %d from host!", i1);
  1097.                     break;
  1098.                 }
  1099.                 break;
  1100.               case 4:
  1101.                 i = 0;
  1102.                 sprintf(temp, "%sBAD-%03d.UUE", argv[5], i);
  1103.                 while (exist(temp))
  1104.                   sprintf(temp, "%sBAD-%03d.UUE", argv[5], ++i);
  1105.                 fnsplit(temp, NULL, NULL, s, s1);
  1106.                 fprintf(stderr, "\n ■ Message %3.3d - %-20s - %s%s", i1, "mailer-daemon", s, s1);
  1107.                 switch (pop_get_nextf(pop_sock, temp, i1)) {
  1108.                   case 0:
  1109.                     fprintf(stderr, "\n ■ Unable to retrieve message %d.", i1);
  1110.                     unlink(temp);
  1111.                     break;
  1112.                   case 1:
  1113.                     break;
  1114.                   case 2:
  1115.                     fprintf(stderr, "\n ■ Unable to delete message %d from host!", i1);
  1116.                     break;
  1117.                 }
  1118.                 break;
  1119.             }
  1120.             i1++;
  1121.           }
  1122.         } else
  1123.           fprintf(stderr, "\n ■ Unknown POP access error - try again later.");
  1124.         pop_shutdown(pop_sock);
  1125.         fcloseall();
  1126.         exit(EXIT_SUCCESS);
  1127.       } else {
  1128.         fprintf(stderr, "\n ■ Unable to log into POP server!");
  1129.         pop_shutdown(pop_sock);
  1130.         fcloseall();
  1131.       }
  1132.     } else
  1133.       fprintf(stderr, "\n ■ POP socket connect failed.");
  1134.     }
  1135.   exit(EXIT_FAILURE);
  1136. }
  1137.