Changeset 411:a60586461eb8 for attach.c
Legend:
- Unmodified
- Added
- Removed
-
attach.c
r364 r411 46 46 char type[STRING]; 47 47 char command[STRING]; 48 char newfile[_POSIX_PATH_MAX] = ""; 48 49 rfc1524_entry *entry = rfc1524_new_entry (); 49 50 short unlink_newfile = 0; 51 int rc = 0; 52 50 53 snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); 51 54 if (rfc1524_mailcap_lookup (a, type, entry, M_COMPOSE)) … … 53 56 if (entry->composecommand || entry->composetypecommand) 54 57 { 55 char newfile[_POSIX_PATH_MAX] = "";56 58 57 59 if (entry->composetypecommand) … … 64 66 dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n", 65 67 a->filename, newfile)); 66 if ( !mutt_rename_file (a->filename, newfile))68 if (symlink (a->filename, newfile) == -1) 67 69 { 68 70 if (!mutt_yesorno ("Can't match nametemplate, continue?", 1)) 69 return 0;71 goto bailout; 70 72 } 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, 79 79 command, sizeof (command))) 80 80 { … … 95 95 { 96 96 mutt_perror ("Failure to open file to parse headers."); 97 return 0;97 goto bailout; 98 98 } 99 99 … … 126 126 { 127 127 mutt_perror ("Failure to open file to strip headers."); 128 return 0;128 goto bailout; 129 129 } 130 130 mutt_copy_stream (fp, tfp); … … 147 147 } 148 148 149 rc = 1; 150 151 bailout: 152 153 if(unlink_newfile) 154 unlink(newfile); 155 149 156 rfc1524_free_entry (&entry); 150 return 1;157 return rc; 151 158 } 152 159 … … 164 171 char type[STRING]; 165 172 char command[STRING]; 173 char newfile[_POSIX_PATH_MAX] = ""; 166 174 rfc1524_entry *entry = rfc1524_new_entry (); 167 175 short unlink_newfile = 0; 176 int rc = 0; 177 168 178 snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); 169 179 if (rfc1524_mailcap_lookup (a, type, entry, M_EDIT)) … … 171 181 if (entry->editcommand) 172 182 { 173 char newfile[_POSIX_PATH_MAX] = "";174 183 175 184 strfcpy (command, entry->editcommand, sizeof (command)); … … 179 188 dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n", 180 189 a->filename, newfile)); 181 if ( mutt_rename_file (a->filename, newfile))190 if (symlink (a->filename, newfile) == -1) 182 191 { 183 192 if (!mutt_yesorno ("Can't match nametemplate, continue?", 1)) 184 return 0;193 goto bailout; 185 194 } 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, 194 201 command, sizeof (command))) 195 202 { … … 208 215 /* On text, default to editor */ 209 216 mutt_edit_file ((!Editor || strcmp ("builtin", Editor) == 0) ? 210 NONULL(Visual) : NONULL(Editor), a->filename);217 NONULL(Visual) : NONULL(Editor), newfile); 211 218 } 212 219 else … … 217 224 } 218 225 226 rc = 1; 227 228 bailout: 229 230 if(unlink_newfile) 231 unlink(newfile); 232 219 233 rfc1524_free_entry (&entry); 220 return 1;234 return rc; 221 235 } 222 236 … … 254 268 rfc1524_entry *entry = NULL; 255 269 int rc = -1; 256 270 int unlink_tempfile = 0; 271 257 272 is_message = mutt_is_message_type(a->type, a->subtype); 258 273 #ifdef _PGPPATH … … 305 320 { 306 321 /* send case: the file is already there */ 307 if ( mutt_rename_file (a->filename, tempfile))322 if (symlink (a->filename, tempfile) == -1) 308 323 { 309 324 if (mutt_yesorno ("Can't match nametemplate, continue?", 1) == M_YES) … … 313 328 } 314 329 else 315 { 316 safe_free ((void **) &a->filename); 317 a->filename = safe_strdup (tempfile); 318 } 330 unlink_tempfile = 1; 319 331 } 320 332 } … … 469 481 if (fp && tempfile[0]) 470 482 mutt_unlink (tempfile); 483 else if (unlink_tempfile) 484 unlink(tempfile); 485 471 486 if (pagerfile[0]) 472 487 mutt_unlink (pagerfile); … … 735 750 pid_t thepid; 736 751 FILE *ifp, *fpout; 737 752 short unlink_newfile = 0; 753 738 754 snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); 739 755 … … 751 767 if (!fp) 752 768 { 753 /* only attempt file move in send mode */ 754 755 if (mutt_rename_file (a->filename, newfile)) 769 if (symlink(a->filename, newfile) == -1) 756 770 { 757 771 if (mutt_yesorno ("Can't match nametemplate, continue?", 1) != M_YES) … … 763 777 } 764 778 else 765 { 766 safe_free ((void **)&a->filename); 767 a->filename = safe_strdup (newfile); 768 } 779 unlink_newfile = 1; 769 780 } 770 781 } … … 804 815 if (fp) 805 816 mutt_unlink (newfile); 817 else if (unlink_newfile) 818 unlink(newfile); 806 819 807 820 rfc1524_free_entry (&entry); … … 811 824 if (!strcasecmp ("text/plain", a->subtype) || 812 825 !strcasecmp ("application/postscript", a->subtype)) 826 { 813 827 return (mutt_pipe_attachment (fp, a, NONULL(PrintCmd), NULL)); 828 } 814 829 else if (mutt_can_decode (a)) 815 830 {
