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

Diff of /mailutils/mh/repl.c

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

revision 1.8 by gray, Thu Jan 16 13:45:28 2003 UTC revision 1.9 by gray, Thu Jan 16 16:18:20 2003 UTC
# Line 18  Line 18 
18  /* MH reply command */  /* MH reply command */
19    
20  #include <mh.h>  #include <mh.h>
21    #include <sys/stat.h>
22    #include <unistd.h>
23    
24  const char *argp_program_version = "reply (" PACKAGE_STRING ")";  const char *argp_program_version = "reply (" PACKAGE_STRING ")";
25  static char doc[] = "GNU MH reply";  static char doc[] = "GNU MH reply";
# Line 62  static struct argp_option options[] = { Line 64  static struct argp_option options[] = {
64    {"width", 'w', N_("NUMBER"), 0, N_("Set output width")},    {"width", 'w', N_("NUMBER"), 0, N_("Set output width")},
65    {"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0,    {"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0,
66     N_("Set the replacement for whatnow program")},     N_("Set the replacement for whatnow program")},
67      {"use", 'u', NULL, 0, N_("Use draft file preserved after the last session") },
68    { N_("\nUse -help switch to obtain the list of traditional MH options. "), 0, 0, OPTION_DOC, "" },    { N_("\nUse -help switch to obtain the list of traditional MH options. "), 0, 0, OPTION_DOC, "" },
69    { 0 }    { 0 }
70  };  };
# Line 108  static mh_msgset_t msgset; Line 111  static mh_msgset_t msgset;
111  static mailbox_t mbox;  static mailbox_t mbox;
112  static int build_only = 0; /* --build flag */  static int build_only = 0; /* --build flag */
113  static int query_mode = 0; /* --query flag */  static int query_mode = 0; /* --query flag */
114    static int use_draft = 0;  /* --use flag */
115    
116  static int  static int
117  decode_cc_flag (const char *opt, const char *arg)  decode_cc_flag (const char *opt, const char *arg)
# Line 163  opt_handler (int key, char *arg, void *u Line 167  opt_handler (int key, char *arg, void *u
167      case 'm':      case 'm':
168        wh_env.draftmessage = arg;        wh_env.draftmessage = arg;
169        break;        break;
170    
171        case 'u':
172          use_draft++;
173          break;
174                
175      case 'w':      case 'w':
176        width = strtoul (arg, NULL, 0);        width = strtoul (arg, NULL, 0);
# Line 204  make_draft () Line 212  make_draft ()
212  {  {
213    int rc;    int rc;
214    message_t msg;    message_t msg;
215    FILE *fp;    int disp = DISP_REPLACE;
216    char buffer[1024];    struct stat st;
217  #define bufsize sizeof(buffer)    
218      /* First check if the draft exists */
219      if (stat (wh_env.draftfile, &st) == 0)
220        {
221          if (use_draft)
222            disp = DISP_USE;
223          else
224            {
225              printf (_("Draft \"%s\" exists (%lu bytes).\n"),
226                      wh_env.draftfile, (unsigned long) st.st_size);
227              disp = mh_disposition (wh_env.draftfile);
228            }
229        }
230    
231    /* FIXME: first check if the draft exists */    switch (disp)
   fp = fopen (wh_env.file, "w+");  
   if (!fp)  
232      {      {
233        mh_error (_("cannot open draft file %s: %s"),      case DISP_QUIT:
234                  wh_env.file, strerror (errno));        exit (0);
235        exit (1);  
236        case DISP_USE:
237          unlink (wh_env.file);
238          rename (wh_env.draftfile, wh_env.file);
239          break;
240              
241        case DISP_REPLACE:
242          unlink (wh_env.draftfile);
243          break;  
244      }      }
245    
246        
247    rc = mailbox_get_message (mbox, msgset.list[0], &msg);    rc = mailbox_get_message (mbox, msgset.list[0], &msg);
248    if (rc)    if (rc)
# Line 225  make_draft () Line 252  make_draft ()
252                  mu_errstring (rc));                  mu_errstring (rc));
253        exit (1);        exit (1);
254      }      }
255      
256    mh_format (&format, msg, msgset.list[0], buffer, bufsize);    if (disp == DISP_REPLACE)
257    fprintf (fp, "%s", buffer);      {
258    fclose (fp);        FILE *fp = fopen (wh_env.file, "w+");
259          char buffer[1024];
260    #define bufsize sizeof(buffer)
261    
262          if (!fp)
263            {
264              mh_error (_("cannot open draft file %s: %s"),
265                        wh_env.file, strerror (errno));
266              exit (1);
267            }
268          mh_format (&format, msg, msgset.list[0], buffer, bufsize);
269          fprintf (fp, "%s", buffer);
270          fclose (fp);
271        }
272    
273    {    {
274      url_t url;      url_t url;
# Line 278  main (int argc, char **argv) Line 318  main (int argc, char **argv)
318      }      }
319        
320    wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0);    wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0);
321        wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0);
322    
323    make_draft ();    make_draft ();
324    
325    /* Exit immediately if --build is given */    /* Exit immediately if --build is given */

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

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