/[mailutils]/mailutils/mh/mh_init.c
ViewVC logotype

Diff of /mailutils/mh/mh_init.c

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

revision 1.24 by gray, Fri Jan 31 15:02:07 2003 UTC revision 1.25 by gray, Sat Feb 8 15:56:54 2003 UTC
# Line 22  Line 22 
22  #include <sys/types.h>  #include <sys/types.h>
23  #include <sys/stat.h>  #include <sys/stat.h>
24  #include <stdarg.h>  #include <stdarg.h>
25    #include <unistd.h>
26    #include <errno.h>
27    #include <fcntl.h>
28    
29  char mh_list_format[] =  char mh_list_format[] =
30  "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>"  "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>"
# Line 503  mh_file_copy (const char *from, const ch Line 506  mh_file_copy (const char *from, const ch
506        
507    return rc;    return rc;
508  }  }
509    
510    mailbox_t
511    mh_open_msg_file (char *file_name)
512    {
513      struct stat st;
514      char *buffer;
515      int fd;
516      size_t len = 0;
517      mailbox_t tmp;
518      stream_t stream;
519      char *p;
520      
521      if (stat (file_name, &st) < 0)
522        {
523          mh_error (_("can't stat file %s: %s"), file_name, strerror (errno));
524          return NULL;
525        }
526    
527      buffer = xmalloc (st.st_size+1);
528      fd = open (file_name, O_RDONLY);
529      if (fd == -1)
530        {
531          mh_error (_("can't open file %s: %s"), file_name, strerror (errno));
532          return NULL;
533        }
534    
535      if (read (fd, buffer, st.st_size) != st.st_size)
536        {
537          mh_error (_("error reading file %s: %s"), file_name, strerror (errno));
538          return NULL;
539        }
540    
541      buffer[st.st_size] = 0;
542      close (fd);
543    
544      if (mailbox_create (&tmp, "/dev/null")
545          || mailbox_open (tmp, MU_STREAM_READ) != 0)
546        {
547          mh_error (_("can't create temporary mailbox"));
548          return NULL;
549        }
550    
551      if (memory_stream_create (&stream, 0, MU_STREAM_RDWR)
552          || stream_open (stream))
553        {
554          mailbox_close (tmp);
555          mh_error (_("can't create temporary stream"));
556          return NULL;
557        }
558    
559      for (p = buffer; *p && isspace (*p); p++)
560        ;
561    
562      if (strncmp (p, "From ", 5))
563        {
564          struct tm *tm;
565          time_t t;
566          char date[80];
567          
568          time(&t);
569          tm = gmtime(&t);
570          strftime (date, sizeof (date),
571                    "From GNU-MH-refile %a %b %e %H:%M:%S %Y%n",
572                    tm);
573          stream_write (stream, date, strlen (date), 0, &len);
574        }      
575    
576      stream_write (stream, p, strlen (p), len, &len);
577      mailbox_set_stream (tmp, stream);
578      if (mailbox_messages_count (tmp, &len)
579          || len < 1)
580        {
581          mh_error (_("input file %s is not a valid message file"), file_name);
582          return NULL;
583        }
584      else if (len > 1)
585        {
586          mh_error (ngettext ("input file %s contains %lu message",
587                              "input file %s contains %lu messages",
588                              len),
589                    (unsigned long) len);
590          return NULL;
591        }
592      free (buffer);
593      return tmp;
594    }

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

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