1
1
#if !defined(lint) && !defined(DOS)
2
static char rcsid[] = "$Id: mimedesc.c 671 2007-08-15 20:28:09Z hubert@u.washington.edu $";
2
static char rcsid[] = "$Id: mimedesc.c 1122 2008-08-02 00:32:26Z hubert@u.washington.edu $";
6
6
* ========================================================================
7
* Copyright 2006-2007 University of Washington
7
* Copyright 2006-2008 University of Washington
9
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
10
* you may not use this file except in compliance with the License.
18
18
#include "../pith/headers.h"
19
19
#include "../pith/mimedesc.h"
20
#include "../pith/mimetype.h"
20
21
#include "../pith/state.h"
21
22
#include "../pith/conf.h"
22
23
#include "../pith/mailview.h"
127
129
a->can_display = MCD_INTERNAL;
128
130
(a+1)->description = NULL;
130
else if(mailcap_can_display(body->type, body->subtype,
133
else if(!strucmp(body->subtype, OUR_PKCS7_ENCLOSURE_SUBTYPE)){
134
memset(a = next_attachment(), 0, sizeof(ATTACH_S));
136
prefix[n = strlen(prefix) - 1] = '\0';
137
a->number = cpystr(prefix);
141
a->number = cpystr("");
143
a->description = body->description ? cpystr(body->description)
146
a->can_display = MCD_INTERNAL;
147
(a+1)->description = NULL;
150
else if(mailcap_can_display(body->type, body->subtype, body, 0)
132
151
|| (can_display_ext
133
= mailcap_can_display(body->type, body->subtype,
134
body->parameter, 1))){
152
= mailcap_can_display(body->type, body->subtype, body, 1))){
135
153
memset(a = next_attachment(), 0, sizeof(ATTACH_S));
137
155
prefix[n = strlen(prefix) - 1] = '\0';
218
236
* This test remains for backward compatibility
220
if((value = body_parameter(body, "name")) != NULL){
238
if(body && (value = parameter_val(body->parameter, "name")) != NULL){
221
239
named = strucmp(value, "Message Body");
222
240
fs_give((void **) &value);
296
body_parameter(struct mail_bodystruct *body, char *attribute)
298
return(rfc2231_get_param(body->parameter, attribute, NULL, NULL));
313
* Returns attribute value or NULL.
314
* Value returned needs to be freed by caller
317
parameter_val(PARAMETER *param, char *attribute)
319
if(!(param && attribute && attribute[0]))
322
return(rfc2231_get_param(param, attribute, NULL, NULL));
327
* Get sender_filename, the filename set by the sender in the attachment.
328
* If a sender_filename buffer is passed in, the answer is copied to it
329
* and a pointer to it is returned. If sender_filename is passed in as NULL
330
* then an allocated copy of the sender filename is returned instead.
331
* If ext_ptr is non-NULL then it is set to point to the extension name.
332
* It is not a separate copy, it points into the string sender_filename.
335
get_filename_parameter(char *sender_filename, size_t sfsize, BODY *body, char **ext_ptr)
338
char *decoded_name = NULL;
339
char *filename = NULL;
349
sender_filename[0] = '\0';
353
* First check for Content-Disposition's "filename" parameter and
354
* if that isn't found for the deprecated Content-Type "name" parameter.
356
if((p = parameter_val(body->disposition.parameter, "filename"))
357
|| (p = parameter_val(body->parameter, "name"))){
360
* If somebody sent us and incorrectly rfc2047 encoded
361
* parameter value instead of what rfc2231 suggest we
362
* grudglingly try to fix it.
364
if(p[0] == '=' && p[1] == '?')
365
decoded_name = (char *) rfc1522_decode_to_utf8((unsigned char *) tmp,
371
filename = last_cmpnt(decoded_name);
374
filename = decoded_name;
379
strncpy(sender_filename, filename, sfsize-1);
380
sender_filename[sfsize-1] = '\0';
383
sender_filename = cpystr(filename);
387
fs_give((void **) &p);
389
/* ext_ptr will end up pointing into sender_filename string */
390
if(ext_ptr && sender_filename)
391
mt_get_file_ext(sender_filename, ext_ptr);
393
return(sender_filename);
414
type_desc(int type, char *subtype, struct mail_body_parameter *params,
415
struct mail_body_parameter *disp_params, int full)
509
type_desc(int type, char *subtype, PARAMETER *params, PARAMETER *disp_params, int full)
417
511
static char type_d[200];
473
567
case TYPEMESSAGE:
474
568
if(full && subtype && strucmp(subtype, "external-body") == 0)
475
if((parmval = rfc2231_get_param(params, "access-type", NULL, NULL)) != NULL){
569
if((parmval = parameter_val(params, "access-type")) != NULL){
476
570
snprintf(p, sizeof(type_d)-(p-type_d), " (%s%s)", full ? "Access: " : "", parmval);
477
571
fs_give((void **) &parmval);
486
580
if(full && type != TYPEMULTIPART && type != TYPEMESSAGE){
487
if((parmval = rfc2231_get_param(params, "name", NULL, NULL)) != NULL){
581
if((parmval = parameter_val(params, "name")) != NULL){
488
582
snprintf(p, sizeof(type_d)-(p-type_d), " (Name: \"%s\")", parmval);
489
583
fs_give((void **) &parmval);
491
else if((parmval = rfc2231_get_param(disp_params, "filename", NULL, NULL)) != NULL){
585
else if((parmval = parameter_val(disp_params, "filename")) != NULL){
492
586
snprintf(p, sizeof(type_d)-(p-type_d), " (Filename: \"%s\")", parmval);
493
587
fs_give((void **) &parmval);
541
635
if(b->type == TYPETEXT)
542
snprintf(string, stringlen-(string-origstring), "%s lines", comatose(b->size.lines));
636
/* lines with no CRLF aren't counted, just add one so it makes more sense */
637
snprintf(string, stringlen-(string-origstring), "%s lines", comatose(b->size.lines+1));
544
639
strncpy(p = string, byte_string(b->size.bytes), stringlen-(string-origstring));
592
687
* Since we're testing for internal displayability, give the
593
688
* internal result over an external viewer
595
effort = mime_can_display(body->type, body->subtype, body->parameter);
690
effort = mime_can_display(body->type, body->subtype, body);
596
691
if(effort == MCD_NONE)
597
692
return(SHOW_NONE);
598
693
else if(effort & MCD_INTERNAL)
692
787
t = &tmp_20k_buf[strlen(tmp_20k_buf)];
790
/* if smime and not attempting print */
791
if(F_OFF(F_DONT_DO_SMIME, ps_global) && is_pkcs7_body(body) && type != 3){
793
sstrncpy(&t, "\015\012", SIZEOF_20KBUF-(t-tmp_20k_buf));
795
if(ps_global->smime && ps_global->smime->need_passphrase){
797
"This part is a PKCS7 S/MIME enclosure. "
798
"You may be able to view it by entering the correct passphrase "
799
"with the \"Decrypt\" command.",
800
SIZEOF_20KBUF-(t-tmp_20k_buf));
804
"This part is a PKCS7 S/MIME enclosure. "
805
"Press \"^E\" for more information.",
806
SIZEOF_20KBUF-(t-tmp_20k_buf));
695
813
sstrncpy(&t, "\015\012", SIZEOF_20KBUF-(t-tmp_20k_buf));
751
mime_can_display(int type, char *subtype, struct mail_body_parameter *params)
869
mime_can_display(int type, char *subtype, BODY *body)
753
return((mailcap_can_display(type, subtype, params, 0)
871
return((mailcap_can_display(type, subtype, body, 0)
755
: (mailcap_can_display(type, subtype, params, 1)
873
: (mailcap_can_display(type, subtype, body, 1)
756
874
? (MCD_EXT_PROMPT | MCD_EXTERNAL) : MCD_NONE))
757
875
| ((type == TYPETEXT || type == TYPEMESSAGE
758
876
|| MIME_VCARD(type,subtype))