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