~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to pith/mimedesc.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2008-09-23 12:17:56 UTC
  • mfrom: (2.1.8 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080923121756-6u4x8bwq89qlzt32
Tags: 2.00+dfsg-2
Update to package description: note that Alpine is no longer in
alpha. (Closes: #499640)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 $";
3
3
#endif
4
4
 
5
5
/*
6
6
 * ========================================================================
7
 
 * Copyright 2006-2007 University of Washington
 
7
 * Copyright 2006-2008 University of Washington
8
8
 *
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.
17
17
 
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"
24
25
#include "../pith/editorial.h"
25
26
#include "../pith/mailpart.h"
26
27
#include "../pith/mailcap.h"
 
28
#include "../pith/smime.h"
27
29
 
28
30
 
29
31
/* internal prototypes */
127
129
            a->can_display     = MCD_INTERNAL;
128
130
            (a+1)->description = NULL;
129
131
        }
130
 
        else if(mailcap_can_display(body->type, body->subtype,
131
 
                                    body->parameter, 0)
 
132
#ifdef SMIME
 
133
        else if(!strucmp(body->subtype, OUR_PKCS7_ENCLOSURE_SUBTYPE)){
 
134
            memset(a = next_attachment(), 0, sizeof(ATTACH_S));
 
135
            if(*prefix){
 
136
                prefix[n = strlen(prefix) - 1] = '\0';
 
137
                a->number                      = cpystr(prefix);
 
138
                prefix[n] = '.';
 
139
            }
 
140
            else
 
141
              a->number = cpystr("");
 
142
 
 
143
            a->description     = body->description ? cpystr(body->description)
 
144
                                                   : cpystr("");
 
145
            a->body            = body;
 
146
            a->can_display     = MCD_INTERNAL;
 
147
            (a+1)->description = NULL;
 
148
        }
 
149
#endif /* SMIME */
 
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));
136
154
            if(*prefix){
137
155
                prefix[n = strlen(prefix) - 1] = '\0';
217
235
            /*
218
236
             * This test remains for backward compatibility
219
237
             */
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);
223
241
            }
238
256
        }
239
257
        else{
240
258
            a->test_deferred = 0;
241
 
            a->can_display = mime_can_display(body->type, body->subtype,
242
 
                                              body->parameter);
 
259
            a->can_display = mime_can_display(body->type, body->subtype, body);
243
260
        }
244
261
 
245
262
        /*
292
309
}
293
310
 
294
311
 
295
 
char *
296
 
body_parameter(struct mail_bodystruct *body, char *attribute)
297
 
{
298
 
    return(rfc2231_get_param(body->parameter, attribute, NULL, NULL));
 
312
/*
 
313
 * Returns attribute value or NULL.
 
314
 * Value returned needs to be freed by caller
 
315
 */
 
316
char *
 
317
parameter_val(PARAMETER *param, char *attribute)
 
318
{
 
319
    if(!(param && attribute && attribute[0]))
 
320
      return(NULL);
 
321
 
 
322
    return(rfc2231_get_param(param, attribute, NULL, NULL));
 
323
}
 
324
 
 
325
 
 
326
/*
 
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.
 
333
 */
 
334
char *
 
335
get_filename_parameter(char *sender_filename, size_t sfsize, BODY *body, char **ext_ptr)
 
336
{
 
337
    char *p = NULL;
 
338
    char *decoded_name = NULL;
 
339
    char *filename = NULL;
 
340
    char  tmp[1000];
 
341
 
 
342
    if(!body)
 
343
      return(NULL);
 
344
 
 
345
    if(sender_filename){
 
346
        if(sfsize <= 0)
 
347
          return(NULL);
 
348
 
 
349
        sender_filename[0] = '\0';
 
350
    }
 
351
 
 
352
    /*
 
353
     * First check for Content-Disposition's "filename" parameter and
 
354
     * if that isn't found for the deprecated Content-Type "name" parameter.
 
355
     */
 
356
    if((p = parameter_val(body->disposition.parameter, "filename"))
 
357
       || (p = parameter_val(body->parameter, "name"))){
 
358
 
 
359
        /*
 
360
         * If somebody sent us and incorrectly rfc2047 encoded
 
361
         * parameter value instead of what rfc2231 suggest we
 
362
         * grudglingly try to fix it.
 
363
         */
 
364
        if(p[0] == '=' && p[1] == '?')
 
365
          decoded_name = (char *) rfc1522_decode_to_utf8((unsigned char *) tmp,
 
366
                                                         sizeof(tmp), p);
 
367
 
 
368
        if(!decoded_name)
 
369
          decoded_name = p;
 
370
 
 
371
        filename = last_cmpnt(decoded_name);
 
372
 
 
373
        if(!filename)
 
374
          filename = decoded_name;
 
375
    }
 
376
 
 
377
    if(filename){
 
378
        if(sender_filename){
 
379
            strncpy(sender_filename, filename, sfsize-1);
 
380
            sender_filename[sfsize-1] = '\0';
 
381
        }
 
382
        else
 
383
          sender_filename = cpystr(filename);
 
384
    }
 
385
 
 
386
    if(p)
 
387
      fs_give((void **) &p);
 
388
 
 
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);
 
392
 
 
393
    return(sender_filename);
299
394
}
300
395
 
301
396
 
411
506
 ----*/
412
507
 
413
508
char *
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)
416
510
{
417
511
    static char  type_d[200];
418
512
    int          i;
429
523
 
430
524
    switch(type){
431
525
      case TYPETEXT:
432
 
        parmval = rfc2231_get_param(params, "charset", NULL, NULL);
 
526
        parmval = parameter_val(params, "charset");
433
527
 
434
528
        if(parmval){
435
529
            for(i = 0; charset_names[i].rfcname; i++)
472
566
 
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);
478
572
          }
484
578
    }
485
579
 
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);
490
584
        }
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);
494
588
        }
539
633
      case ENC8BIT :
540
634
      case ENC7BIT :
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));
543
638
        else
544
639
          strncpy(p = string, byte_string(b->size.bytes), stringlen-(string-origstring));
545
640
 
592
687
         * Since we're testing for internal displayability, give the
593
688
         * internal result over an external viewer
594
689
         */
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)
691
786
 
692
787
    t = &tmp_20k_buf[strlen(tmp_20k_buf)];
693
788
 
 
789
#ifdef SMIME
 
790
    /* if smime and not attempting print */
 
791
    if(F_OFF(F_DONT_DO_SMIME, ps_global) && is_pkcs7_body(body) && type != 3){
 
792
 
 
793
        sstrncpy(&t, "\015\012", SIZEOF_20KBUF-(t-tmp_20k_buf));
 
794
        
 
795
        if(ps_global->smime && ps_global->smime->need_passphrase){
 
796
            sstrncpy(&t,
 
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));
 
801
        }
 
802
        else{
 
803
            sstrncpy(&t,
 
804
            "This part is a PKCS7 S/MIME enclosure. "
 
805
            "Press \"^E\" for more information.",
 
806
            SIZEOF_20KBUF-(t-tmp_20k_buf));
 
807
        }
 
808
    
 
809
    } else 
 
810
#endif
 
811
 
694
812
    if(type){
695
813
        sstrncpy(&t, "\015\012", SIZEOF_20KBUF-(t-tmp_20k_buf));
696
814
        switch(type) {
748
866
 
749
867
 ----*/
750
868
int
751
 
mime_can_display(int type, char *subtype, struct mail_body_parameter *params)
 
869
mime_can_display(int type, char *subtype, BODY *body)
752
870
{
753
 
    return((mailcap_can_display(type, subtype, params, 0)
 
871
    return((mailcap_can_display(type, subtype, body, 0)
754
872
              ? MCD_EXTERNAL 
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))