Changeset 411:a60586461eb8 for attach.c

Show
Ignore:
Timestamp:
1998-08-25 15:19:47 (10 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
mutt-0-94
Message:

[patch-0.94.4i.tlr.nametemplate.1] Fix nametemplate
support: We should not move the user's files around just
to make them match mailcap's idea of their file name.
This patch uses symbolic links instead.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • attach.c

    r364 r411  
    4646  char type[STRING]; 
    4747  char command[STRING]; 
     48  char newfile[_POSIX_PATH_MAX] = ""; 
    4849  rfc1524_entry *entry = rfc1524_new_entry (); 
    49  
     50  short unlink_newfile = 0; 
     51  int rc = 0; 
     52   
    5053  snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); 
    5154  if (rfc1524_mailcap_lookup (a, type, entry, M_COMPOSE)) 
     
    5356    if (entry->composecommand || entry->composetypecommand) 
    5457    { 
    55       char newfile[_POSIX_PATH_MAX] = ""; 
    5658 
    5759      if (entry->composetypecommand) 
     
    6466        dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n", 
    6567                                  a->filename, newfile)); 
    66         if (!mutt_rename_file (a->filename, newfile)) 
     68        if (symlink (a->filename, newfile) == -1) 
    6769        { 
    6870          if (!mutt_yesorno ("Can't match nametemplate, continue?", 1)) 
    69             return 0; 
     71            goto bailout; 
    7072        } 
    71         else 
    72         { 
    73           safe_free ((void **) &a->filename); 
    74           a->filename = safe_strdup (newfile); 
    75         } 
    76       } 
    77  
    78       if (rfc1524_expand_command (a, a->filename, type, 
     73        unlink_newfile = 1; 
     74      } 
     75      else 
     76        strfcpy(newfile, a->filename, sizeof(newfile)); 
     77       
     78      if (rfc1524_expand_command (a, newfile, type, 
    7979                                      command, sizeof (command))) 
    8080      { 
     
    9595          { 
    9696            mutt_perror ("Failure to open file to parse headers."); 
    97             return 0; 
     97            goto bailout; 
    9898          } 
    9999 
     
    126126            { 
    127127              mutt_perror ("Failure to open file to strip headers."); 
    128               return 0; 
     128              goto bailout; 
    129129            } 
    130130            mutt_copy_stream (fp, tfp); 
     
    147147  } 
    148148 
     149  rc = 1; 
     150   
     151  bailout: 
     152   
     153  if(unlink_newfile) 
     154    unlink(newfile); 
     155 
    149156  rfc1524_free_entry (&entry); 
    150   return 1; 
     157  return rc; 
    151158} 
    152159 
     
    164171  char type[STRING]; 
    165172  char command[STRING]; 
     173  char newfile[_POSIX_PATH_MAX] = ""; 
    166174  rfc1524_entry *entry = rfc1524_new_entry (); 
    167  
     175  short unlink_newfile = 0; 
     176  int rc = 0; 
     177   
    168178  snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); 
    169179  if (rfc1524_mailcap_lookup (a, type, entry, M_EDIT)) 
     
    171181    if (entry->editcommand) 
    172182    { 
    173       char newfile[_POSIX_PATH_MAX] = ""; 
    174183 
    175184      strfcpy (command, entry->editcommand, sizeof (command)); 
     
    179188        dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n", 
    180189                                  a->filename, newfile)); 
    181         if (mutt_rename_file (a->filename, newfile)) 
     190        if (symlink (a->filename, newfile) == -1) 
    182191        { 
    183192          if (!mutt_yesorno ("Can't match nametemplate, continue?", 1)) 
    184             return 0; 
     193            goto bailout; 
    185194        } 
    186         else 
    187         { 
    188           safe_free ((void **) &a->filename); 
    189           a->filename = safe_strdup (newfile); 
    190         } 
    191       } 
    192  
    193       if (rfc1524_expand_command (a, a->filename, type, 
     195        unlink_newfile = 1; 
     196      } 
     197      else 
     198        strfcpy(newfile, a->filename, sizeof(newfile)); 
     199 
     200      if (rfc1524_expand_command (a, newfile, type, 
    194201                                      command, sizeof (command))) 
    195202      { 
     
    208215    /* On text, default to editor */ 
    209216    mutt_edit_file ((!Editor || strcmp ("builtin", Editor) == 0) ?  
    210                     NONULL(Visual) : NONULL(Editor), a->filename); 
     217                    NONULL(Visual) : NONULL(Editor), newfile); 
    211218  } 
    212219  else 
     
    217224  } 
    218225 
     226  rc = 1; 
     227   
     228  bailout: 
     229   
     230  if(unlink_newfile) 
     231    unlink(newfile); 
     232   
    219233  rfc1524_free_entry (&entry); 
    220   return 1; 
     234  return rc; 
    221235} 
    222236 
     
    254268  rfc1524_entry *entry = NULL; 
    255269  int rc = -1; 
    256  
     270  int unlink_tempfile = 0; 
     271   
    257272  is_message = mutt_is_message_type(a->type, a->subtype); 
    258273#ifdef _PGPPATH 
     
    305320      { 
    306321        /* send case: the file is already there */ 
    307         if (mutt_rename_file (a->filename, tempfile)) 
     322        if (symlink (a->filename, tempfile) == -1) 
    308323        { 
    309324          if (mutt_yesorno ("Can't match nametemplate, continue?", 1) == M_YES) 
     
    313328        } 
    314329        else 
    315         { 
    316           safe_free ((void **) &a->filename); 
    317           a->filename = safe_strdup (tempfile); 
    318         } 
     330          unlink_tempfile = 1; 
    319331      } 
    320332    } 
     
    469481  if (fp && tempfile[0]) 
    470482    mutt_unlink (tempfile); 
     483  else if (unlink_tempfile) 
     484    unlink(tempfile); 
     485 
    471486  if (pagerfile[0]) 
    472487    mutt_unlink (pagerfile); 
     
    735750  pid_t thepid; 
    736751  FILE *ifp, *fpout; 
    737  
     752  short unlink_newfile = 0; 
     753   
    738754  snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); 
    739755 
     
    751767      if (!fp) 
    752768      { 
    753         /* only attempt file move in send mode */ 
    754  
    755         if (mutt_rename_file (a->filename, newfile)) 
     769        if (symlink(a->filename, newfile) == -1) 
    756770        { 
    757771          if (mutt_yesorno ("Can't match nametemplate, continue?", 1) != M_YES) 
     
    763777        } 
    764778        else 
    765         { 
    766           safe_free ((void **)&a->filename); 
    767           a->filename = safe_strdup (newfile); 
    768         } 
     779          unlink_newfile = 1; 
    769780      } 
    770781    } 
     
    804815    if (fp) 
    805816      mutt_unlink (newfile); 
     817    else if (unlink_newfile) 
     818      unlink(newfile); 
    806819 
    807820    rfc1524_free_entry (&entry); 
     
    811824  if (!strcasecmp ("text/plain", a->subtype) || 
    812825      !strcasecmp ("application/postscript", a->subtype)) 
     826  { 
    813827    return (mutt_pipe_attachment (fp, a, NONULL(PrintCmd), NULL)); 
     828  } 
    814829  else if (mutt_can_decode (a)) 
    815830  {