/[mailutils]/mailutils/mailbox/mbx_mh.c
ViewVC logotype

Diff of /mailutils/mailbox/mbx_mh.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38 by gray, Thu Feb 13 16:31:32 2003 UTC revision 1.39 by gray, Sat Feb 22 22:31:52 2003 UTC
# Line 504  _mh_message_save (struct _mh_data *mhd, Line 504  _mh_message_save (struct _mh_data *mhd,
504    char *name = NULL, *buf = NULL, *msg_name;    char *name = NULL, *buf = NULL, *msg_name;
505    size_t n, off = 0;    size_t n, off = 0;
506    size_t bsize;    size_t bsize;
507    size_t nlines;    size_t nlines, nbytes;
508    size_t new_body_start, new_header_lines;    size_t new_body_start, new_header_lines;
509    FILE *fp;    FILE *fp;
510    message_t msg = mhm->message;    message_t msg = mhm->message;
# Line 517  _mh_message_save (struct _mh_data *mhd, Line 517  _mh_message_save (struct _mh_data *mhd,
517        
518    fp = _mh_tempfile (mhm->mhd, &name);    fp = _mh_tempfile (mhm->mhd, &name);
519    if (!fp)    if (!fp)
520      {      return errno;
       free (mhm);  
       return errno;  
     }  
521    
522    message_size (msg, &bsize);    message_size (msg, &bsize);
523    
# Line 530  _mh_message_save (struct _mh_data *mhd, Line 527  _mh_message_save (struct _mh_data *mhd,
527        break;        break;
528    
529    if (!bsize)    if (!bsize)
530      {      return ENOMEM;
       free (mhm);  
       return ENOMEM;  
     }  
531    
532    /* Copy flags */    /* Copy flags */
533    message_get_header (msg, &hdr);    message_get_header (msg, &hdr);
534    header_get_stream (hdr, &stream);    header_get_stream (hdr, &stream);
535    off = 0;    off = 0;
536    nlines = 0;    nlines = nbytes = 0;
537    while ((status = stream_readline (stream, buf, bsize, off, &n)) == 0    while ((status = stream_readline (stream, buf, bsize, off, &n)) == 0
538           && n != 0)           && n != 0)
539      {      {
540        if (_mh_delim(buf))        if (_mh_delim(buf))
541          break;          break;
542    
       nlines++;  
   
543        if (!(strncasecmp (buf, "status:", 7) == 0        if (!(strncasecmp (buf, "status:", 7) == 0
544              || strncasecmp (buf, "x-imapbase:", 11) == 0              || strncasecmp (buf, "x-imapbase:", 11) == 0
545              || strncasecmp (buf, "x-uid:", 6) == 0              || strncasecmp (buf, "x-uid:", 6) == 0
546              || strncasecmp (buf, MU_HEADER_ENV_DATE ":", sizeof (MU_HEADER_ENV_DATE)) == 0              || strncasecmp (buf, MU_HEADER_ENV_DATE ":", sizeof (MU_HEADER_ENV_DATE)) == 0
547              || strncasecmp (buf, MU_HEADER_ENV_SENDER ":", sizeof (MU_HEADER_ENV_SENDER)) == 0))              || strncasecmp (buf, MU_HEADER_ENV_SENDER ":", sizeof (MU_HEADER_ENV_SENDER)) == 0))
548          fprintf (fp, "%s", buf);          {
549              nlines++;
550              nbytes += fprintf (fp, "%s", buf);
551            }
552          
553        off += n;        off += n;
554      }      }
555    
   new_header_lines = nlines;  
   new_body_start = off;  
   
556    /* Add imapbase */    /* Add imapbase */
557    if (!mhd->msg_head || (mhd->msg_head == mhm)) /*FIXME*/    if (!mhd->msg_head || (mhd->msg_head == mhm)) /*FIXME*/
558      {      {
559        fprintf (fp, "X-IMAPbase: %lu %u\n",        nbytes += fprintf (fp, "X-IMAPbase: %lu %u\n",
560                 (unsigned long) mhd->uidvalidity, (unsigned) _mh_next_seq(mhd));                           (unsigned long) mhd->uidvalidity,
561                             (unsigned) _mh_next_seq(mhd));
562        nlines++;        nlines++;
563      }      }
564        
# Line 575  _mh_message_save (struct _mh_data *mhd, Line 569  _mh_message_save (struct _mh_data *mhd,
569        char *p = buffer;        char *p = buffer;
570        while (isspace (*p))        while (isspace (*p))
571          p++;          p++;
572        fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, p);        nbytes += fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, p);
573    
574        if (*p && p[strlen (p) - 1] != '\n')        if (*p && p[strlen (p) - 1] != '\n')
575          fprintf (fp, "\n");          nbytes += fprintf (fp, "\n");
576                
577        nlines++;        nlines++;
578      }      }
# Line 592  _mh_message_save (struct _mh_data *mhd, Line 586  _mh_message_save (struct _mh_data *mhd,
586    /* Add status */    /* Add status */
587    message_get_attribute (msg, &attr);    message_get_attribute (msg, &attr);
588    attribute_to_string (attr, buf, bsize, &n);    attribute_to_string (attr, buf, bsize, &n);
589    fprintf (fp, "%s", buf);    if (n)
590    fprintf (fp, "\n");      {
591    nlines += 2;        nbytes += fprintf (fp, "%s", buf);
592          nlines++;
593        }
594      nbytes += fprintf (fp, "\n");
595      nlines++;
596        
597      new_header_lines = nlines;
598      new_body_start = nbytes;
599    
600    /* Copy message body */    /* Copy message body */
601    
602    message_get_body (msg, &body);    message_get_body (msg, &body);
# Line 610  _mh_message_save (struct _mh_data *mhd, Line 611  _mh_message_save (struct _mh_data *mhd,
611            nlines++;            nlines++;
612        fwrite (buf, 1, n, fp);        fwrite (buf, 1, n, fp);
613        off += n;        off += n;
614          nbytes += n;
615      }      }
616    
617    mhm->header_lines = new_header_lines;    mhm->header_lines = new_header_lines;
618    mhm->body_start = new_body_start;    mhm->body_start = new_body_start;
619    mhm->body_lines = nlines;    mhm->body_lines = nlines;
620    mhm->body_end = off;    mhm->body_end = nbytes;
621    
622    free (buf);    free (buf);
623    fclose (fp);    fclose (fp);
# Line 1215  mh_message_stream_open (struct _mh_messa Line 1217  mh_message_stream_open (struct _mh_messa
1217    struct _mh_data *mhd = mhm->mhd;    struct _mh_data *mhd = mhm->mhd;
1218    char *filename = NULL;    char *filename = NULL;
1219    int status;    int status;
1220      int flags = MU_STREAM_ALLOW_LINKS;
1221    filename = _mh_message_name (mhm, mhm->deleted);    filename = _mh_message_name (mhm, mhm->deleted);
1222    
1223    if (!filename)    if (!filename)
1224      return ENOMEM;      return ENOMEM;
1225    
1226    status = file_stream_create (&mhm->stream, filename,    /* The message should be at least readable */
1227                                 mhd->mailbox->flags | MU_STREAM_ALLOW_LINKS);    if (mhd->mailbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))
1228        flags |= MU_STREAM_RDWR;
1229      else
1230        flags |= MU_STREAM_READ;
1231      status = file_stream_create (&mhm->stream, filename, flags);
1232    
1233    free (filename);    free (filename);
1234    

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26