home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B30.ZIP / POP.C < prev    next >
Text File  |  1997-07-02  |  34KB  |  1,159 lines

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