Changeset 411:a60586461eb8
Legend:
- Unmodified
- Added
- Removed
-
TODO
r407 r411 110 110 111 111 112 - Re-visit nametemplate support. Currently, we use 113 symbolic links in our temporary directory for this. 114 115 112 116 - BODY struct should probably have a pointer to its 113 117 corresponding HEADER struct. this is needed for … … 116 120 STATE struct so that all of the MIME handlers can look 117 121 up the corresponding HEADERs if need be? 118 119 - rfc1524_expand_filename() doesn't work as expected, as120 it doesn't honor $tmpdir under some conditions if121 matching nametemplates exist.122 122 123 123 - option to not include attachments in replies -
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 { -
rfc1524.c
r348 r411 56 56 char buf[LONG_STRING]; 57 57 58 while (command[x] && x<clen && y<sizeof(buf)) { 58 while (command[x] && x<clen && y<sizeof(buf)) 59 { 59 60 if (command[x] == '\\') { 60 61 x++; 61 62 buf[y++] = command[x++]; 62 63 } 63 else if (command[x] == '%') { 64 else if (command[x] == '%') 65 { 64 66 x++; 65 if (command[x] == '{') { 67 if (command[x] == '{') 68 { 66 69 char param[STRING]; 67 70 int z = 0; … … 422 425 char tmp[_POSIX_PATH_MAX]; 423 426 char *period; 424 427 size_t sl; 428 425 429 strfcpy (buf, NONULL (Tempdir), sizeof (buf)); 426 430 mutt_expand_path (buf, sizeof (buf)); … … 443 447 { 444 448 *period = '.'; 445 strcat (s, period); 446 } 447 } 448 } 449 450 /* This routine expands the filename given to match the format of the 451 * nametemplate given. It returns various values based on what operations 452 * it performs. 453 * 449 sl = strlen(s); 450 strfcpy(s + sl, period, l - sl); 451 } 452 } 453 } 454 455 /* This routine will create a _temporary_ filename matching the 456 * name template given if this needs to be done. 457 * 458 * Please note that only the last path element of the 459 * template and/or the old file name will be used for the 460 * comparison and the temporary file name. 461 * 454 462 * Returns 0 if oldfile is fine as is. 455 463 * Returns 1 if newfile specified 456 464 */ 465 466 static void strnfcpy(char *d, char *s, size_t siz, size_t len) 467 { 468 if(len > siz) 469 len = siz - 1; 470 strfcpy(d, s, len); 471 } 457 472 458 473 int rfc1524_expand_filename (char *nametemplate, … … 461 476 size_t nflen) 462 477 { 463 int z = 0; 464 int i = 0, j = 0; 465 int lmatch = TRUE; 466 int match = TRUE; 467 size_t len = 0; 478 int i, j, k, ps, r; 468 479 char *s; 469 480 short lmatch = 0, rmatch = 0; 481 char left[_POSIX_PATH_MAX]; 482 char right[_POSIX_PATH_MAX]; 483 470 484 newfile[0] = 0; 471 485 486 /* first, ignore leading path components. 487 */ 488 472 489 if (nametemplate && (s = strrchr (nametemplate, '/'))) 473 490 nametemplate = s + 1; 474 491 475 492 if (oldfile && (s = strrchr (oldfile, '/'))) 476 { 477 len = s - oldfile + 1; 478 if (len > nflen) 479 len = nflen; 480 strfcpy (newfile, oldfile, len + 1); 481 oldfile += len; 482 } 483 484 /* If nametemplate is NULL, create a newfile from oldfile and return 0 */ 493 oldfile = s + 1; 494 485 495 if (!nametemplate) 486 496 { 487 497 if (oldfile) 488 498 strfcpy (newfile, oldfile, nflen); 489 mutt_adv_mktemp (newfile, nflen); 499 } 500 else if (!oldfile) 501 { 502 snprintf (newfile, nflen, nametemplate, "mutt"); 503 } 504 else /* oldfile && nametemplate */ 505 { 506 507 /* first, compare everything left from the "%s" 508 * (if there is one). 509 */ 510 511 lmatch = 1; ps = 0; 512 for(i = 0; nametemplate[i]; i++) 513 { 514 if(nametemplate[i] == '%' && nametemplate[i+1] == 's') 515 { 516 ps = 1; 517 break; 518 } 519 520 /* note that the following will _not_ read beyond oldfile's end. */ 521 522 if(lmatch && nametemplate[i] != oldfile[i]) 523 lmatch = 0; 524 } 525 526 if(ps) 527 { 528 529 /* If we had a "%s", check the rest. */ 530 531 /* now, for the right part: compare everything right from 532 * the "%s" to the final part of oldfile. 533 * 534 * The logic here is as follows: 535 * 536 * - We start reading from the end. 537 * - There must be a match _right_ from the "%s", 538 * thus the i + 2. 539 * - If there was a left hand match, this stuff 540 * must not be counted again. That's done by the 541 * condition (j >= (lmatch ? i : 0)). 542 */ 543 544 rmatch = 1; 545 546 for(r = 0, j = strlen(oldfile) - 1, k = strlen(nametemplate) - 1 ; 547 j >= (lmatch ? i : 0) && k >= i + 2; 548 j--, k--) 549 { 550 if(nametemplate[k] != oldfile[j]) 551 { 552 rmatch = 0; 553 break; 554 } 555 } 556 557 /* Now, check if we had a full match. */ 558 559 if(k >= i + 2) 560 rmatch = 0; 561 562 if(lmatch) *left = 0; 563 else strnfcpy(left, nametemplate, sizeof(left), i); 564 565 if(rmatch) *right = 0; 566 else strfcpy(right, nametemplate + i + 2, sizeof(right)); 567 568 snprintf(newfile, nflen, "%s%s%s", left, oldfile, right); 569 } 570 else 571 { 572 /* no "%s" in the name template. */ 573 strfcpy(newfile, nametemplate, nflen); 574 } 575 } 576 577 mutt_adv_mktemp(newfile, nflen); 578 579 if(rmatch && lmatch) 490 580 return 0; 491 } 492 493 /* If oldfile is NULL, just return a newfile name */ 494 if (!oldfile) 495 { 496 snprintf (newfile, nflen, nametemplate, "mutt"); 497 mutt_adv_mktemp (newfile, nflen); 498 return 0; 499 } 500 501 /* Next, attempt to determine if the oldfile already matches nametemplate */ 502 /* Nametemplate is of the form pre%spost, only replace pre or post if 503 * they don't already match the oldfilename */ 504 /* Test pre */ 505 506 if ((s = strrchr (nametemplate, '%')) != NULL) 507 { 508 newfile[len] = '\0'; 509 510 z = s - nametemplate; 511 512 for (i = 0; i < z && i < nflen; i++) 513 { 514 if (oldfile[i] != nametemplate[i]) 515 { 516 lmatch=FALSE; 517 break; 518 } 519 } 520 521 if (!lmatch) 522 { 523 match = FALSE; 524 i = nflen - len; 525 if (i > z) 526 i = z; 527 strfcpy (newfile + len, nametemplate, i); 528 } 529 530 strfcpy (newfile + strlen (newfile), 531 oldfile, nflen - strlen (newfile)); 532 533 dprint (1, (debugfile,"template: %s, oldfile: %s, newfile: %s\n", 534 nametemplate, oldfile, newfile)); 535 536 /* test post */ 537 lmatch = TRUE; 538 539 for (z += 2, i = strlen (oldfile) - 1, j = strlen (nametemplate) - 1; 540 i && j > z; i--, j--) 541 if (oldfile[i] != nametemplate[j]) 542 { 543 lmatch = FALSE; 544 break; 545 } 546 547 if (!lmatch) 548 { 549 match = FALSE; 550 strfcpy (newfile + strlen (newfile), 551 nametemplate + z, nflen - strlen (newfile)); 552 } 553 554 if (match) 555 return 0; 556 581 else 557 582 return 1; 558 } 559 else 560 { 561 /* no %s in nametemplate, graft unto path of oldfile */ 562 strfcpy (newfile, nametemplate, nflen); 563 return 1; 564 } 565 } 566 567 /* For nametemplate support, we may need to rename a file. 568 * If rfc1524_expand_command() is used on a recv'd message, then 583 584 } 585 586 /* If rfc1524_expand_command() is used on a recv'd message, then 569 587 * the filename doesn't exist yet, but if its used while sending a message, 570 588 * then we need to rename the existing file.
