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

  1. /*
  2.  * Copyright (c) 1997 by Qualcomm Incorporated.
  3.  */
  4.  
  5. #include <config.h>
  6. #include <stdio.h>
  7. #include <sys/types.h>
  8. #include <sys/file.h>
  9. #include <sys/wait.h>
  10. #include <ctype.h>
  11. #include <string.h>
  12. #ifndef HAVE_INDEX
  13. # define index(s,c)        strchr(s,c)
  14. #endif
  15. #if HAVE_STRINGS_H
  16. #include <strings.h>
  17. #endif
  18.  
  19. #include "popper.h"
  20.  
  21. /*
  22.  *  uidl:   POP UIDL function to list messages by message-ids
  23.  */
  24.  
  25. pop_uidl (p)
  26. POP     *   p;
  27. {
  28.     char                    buffer[MAXLINELEN];     /*  Read buffer */
  29.     char            *nl, *bp;
  30.     MsgInfoList         *   mp;         /*  Pointer to message info list */
  31.     int msg_id = 0, x;
  32.     int len = 0;
  33.  
  34.     if (p->parm_count == 1) {
  35.       len = strlen(p->pop_parm[1]);
  36.  
  37.       /*  Convert the parameter into an integer */
  38.       msg_id = atoi(p->pop_parm[1]);
  39.     }
  40.  
  41.     /*  Is requested message out of range? */
  42.     if (len > 0 && msg_id == 0)
  43.     {
  44.       return (pop_msg (p,POP_FAILURE,"Parameter must be a number (range 1 to %d)", p->msg_count));
  45.     }
  46.  
  47.     if (len > 0 && (msg_id < 1 || msg_id > p->msg_count))
  48.       return (pop_msg (p,POP_FAILURE,
  49.           "Message out of range.  %d messages in mail drop.",p->msg_count));
  50.  
  51.     if (msg_id > 0) {
  52.       /*  Get a pointer to the message in the message list */
  53.       mp = &p->mlp[msg_id-1];
  54.  
  55.       if (mp->del_flag) {
  56.         return (pop_msg (p,POP_FAILURE,
  57.                 "Message %d has been marked for deletion.",msg_id));
  58.       } else {
  59.  
  60.     sprintf(buffer, "%d %s", msg_id, mp->uidl_str);
  61.         if (nl = index(buffer, NEWLINE)) *nl = 0;
  62.     return (pop_msg (p,POP_SUCCESS, buffer));
  63.       }
  64.     } else {
  65.     /* yes, we can do this */
  66.     pop_msg (p,POP_SUCCESS,"uidl command accepted.");
  67.  
  68.     for (x = 1; x <= p->msg_count; x++)
  69.     {
  70.         /*  Get a pointer to the message in the message list */
  71.         mp = &p->mlp[x-1];
  72.  
  73.         /*  Is the message flagged for deletion? */
  74.         if (mp->del_flag) continue;
  75.  
  76.         sprintf(buffer, "%d %s", x, mp->uidl_str);
  77. /*        nl = index(mp->uidl_str, NEWLINE); */
  78.         pop_sendline(p, buffer);
  79. /*
  80.         if (!nl)
  81.         fprintf(p->output, "\n");
  82. */
  83.         }
  84.     }
  85.  
  86.     /*  "." signals the end of a multi-line transmission */
  87.     (void)fputs(".\r\n",p->output);
  88.     (void)fflush(p->output);
  89.  
  90.     return(POP_SUCCESS);
  91. }
  92.  
  93. /*
  94.  *  euidl:   POP EUIDL function to list messages by message-ids and adds
  95.  *         message size and From: header text as well.  This is to help
  96.  *         the Newton do some pre-filtering before downloading messages.
  97.  */
  98.  
  99. char *
  100. from_hdr(p, mp)
  101.      POP         *p;
  102.      MsgInfoList *mp;
  103. {
  104.   char buf[MAXLINELEN], *cp;
  105.  
  106.     fseek(p->drop, mp->offset, 0);
  107.     while (fgets(buf, sizeof(buf), p->drop) != NULL) {
  108.       if (buf[0] == '\n') break;    /* From header not found */
  109.       if (!strncasecmp("From:", buf, 5)) {
  110.     cp = index(buf, ':');
  111.     while (*++cp && (*cp == ' ' || *cp == '\t'));
  112.     return(cp);
  113.       }
  114.     }
  115.     return("");
  116. }
  117.  
  118. pop_euidl (p)
  119. POP     *   p;
  120. {
  121.     char                    buffer[MAXLINELEN];     /*  Read buffer */
  122.     char            *nl, *bp;
  123.     MsgInfoList         *   mp;         /*  Pointer to message info list */
  124.     int msg_id = 0, x;
  125.     int len = 0;
  126.  
  127.     if (p->parm_count == 1) {
  128.       len = strlen(p->pop_parm[1]);
  129.  
  130.       /*  Convert the parameter into an integer */
  131.       msg_id = atoi(p->pop_parm[1]);
  132.     }
  133.  
  134.     /*  Is requested message out of range? */
  135.     if (len > 0 && msg_id == 0)
  136.     {
  137.       return (pop_msg (p,POP_FAILURE,"Parameter must be a number (range 1 to %d)", p->msg_count));
  138.     }
  139.  
  140.     if (len > 0 && (msg_id < 1 || msg_id > p->msg_count))
  141.       return (pop_msg (p,POP_FAILURE,
  142.           "Message out of range.  %d messages in mail drop.",p->msg_count));
  143.  
  144.     if (msg_id > 0) {
  145.       /*  Get a pointer to the message in the message list */
  146.       mp = &p->mlp[msg_id-1];
  147.  
  148.       if (mp->del_flag) {
  149.         return (pop_msg (p,POP_FAILURE,
  150.                 "Message %d has been marked for deletion.",msg_id));
  151.       } else {
  152.  
  153.     sprintf(buffer, "%d %s", msg_id, mp->uidl_str);
  154.         if (nl = index(buffer, NEWLINE)) *nl = 0;
  155.     sprintf(buffer, "%s %d %s", buffer, mp->length, from_hdr(p, mp));
  156.     return (pop_msg (p,POP_SUCCESS, buffer));
  157.       }
  158.     } else {
  159.     /* yes, we can do this */
  160.     pop_msg (p,POP_SUCCESS,"uidl command accepted.");
  161.  
  162.     for (x = 1; x <= p->msg_count; x++)
  163.     {
  164.         /*  Get a pointer to the message in the message list */
  165.         mp = &p->mlp[x-1];
  166.  
  167.         /*  Is the message flagged for deletion? */
  168.         if (mp->del_flag) continue;
  169.  
  170.         sprintf(buffer, "%d %s", x, mp->uidl_str);
  171.         if (nl = index(buffer, NEWLINE)) *nl = 0;        
  172.         sprintf(buffer, "%s %d %s", buffer, mp->length, from_hdr(p, mp));
  173.         pop_sendline(p, buffer);
  174.         }
  175.     }
  176.  
  177.     /*  "." signals the end of a multi-line transmission */
  178.     (void)fputs(".\r\n",p->output);
  179.     (void)fflush(p->output);
  180.  
  181.     return(POP_SUCCESS);
  182. }
  183.  
  184.