src/etpan_mime.c
changeset 154 3ba2cbfcef1d
parent 153 2402d3d340e2
child 155 a131cef4a937
     1.1 --- a/src/etpan_mime.c	Sat Mar 28 22:11:57 2015 +0100
     1.2 +++ b/src/etpan_mime.c	Sun Mar 29 11:23:35 2015 +0200
     1.3 @@ -596,6 +596,40 @@
     1.4      return content;
     1.5  }
     1.6  
     1.7 +char * _get_filename(struct mailmime *mime)
     1.8 +{
     1.9 +    clist * _fieldlist = NULL;
    1.10 +
    1.11 +    assert(mime);
    1.12 +
    1.13 +    if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list)
    1.14 +        _fieldlist = mime->mm_mime_fields->fld_list;
    1.15 +    else
    1.16 +        return NULL;
    1.17 +
    1.18 +    clistiter *cur;
    1.19 +    for (cur = clist_begin(_fieldlist); cur; cur = clist_next(cur)) {
    1.20 +        struct mailmime_field * _field = clist_content(cur);
    1.21 +        if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
    1.22 +            if (_field->fld_data.fld_disposition &&
    1.23 +                    _field->fld_data.fld_disposition->dsp_parms) {
    1.24 +                clist * _parmlist =
    1.25 +                        _field->fld_data.fld_disposition->dsp_parms;
    1.26 +                clistiter *cur2;
    1.27 +                for (cur2 = clist_begin(_parmlist); cur2; cur2 =
    1.28 +                        clist_next(cur2)) {
    1.29 +                    struct mailmime_parameter * param = clist_content(cur2);
    1.30 +                    if (param && (param->pa_name == NULL || 
    1.31 +                            strcmp("filename", param->pa_name) == 0))
    1.32 +                        return param->pa_value;
    1.33 +                }
    1.34 +            }
    1.35 +        }
    1.36 +    }
    1.37 +
    1.38 +    return NULL;
    1.39 +}
    1.40 +
    1.41  bool parameter_has_value(
    1.42          struct mailmime_content *content,       
    1.43          const char *name,
    1.44 @@ -672,3 +706,56 @@
    1.45      return false;
    1.46  }
    1.47  
    1.48 +char * _get_content_type(struct mailmime_content *content)
    1.49 +{
    1.50 +    const char *_type;
    1.51 +
    1.52 +    assert(content);
    1.53 +
    1.54 +    if (content->ct_subtype == NULL)
    1.55 +        return NULL;
    1.56 +
    1.57 +    if (content->ct_type && content->ct_type->tp_data.tp_discrete_type) {
    1.58 +        size_t len;
    1.59 +        char *type;
    1.60 +
    1.61 +        switch  (content->ct_type->tp_data.tp_discrete_type->dt_type) {
    1.62 +            case MAILMIME_DISCRETE_TYPE_TEXT:
    1.63 +                _type = "text";
    1.64 +                break;
    1.65 +            case MAILMIME_DISCRETE_TYPE_IMAGE:
    1.66 +                _type = "image";
    1.67 +                break;
    1.68 +            case MAILMIME_DISCRETE_TYPE_AUDIO:
    1.69 +                _type = "audio";
    1.70 +                break;
    1.71 +            case MAILMIME_DISCRETE_TYPE_VIDEO:
    1.72 +                _type = "video";
    1.73 +                break;
    1.74 +            case MAILMIME_DISCRETE_TYPE_APPLICATION:
    1.75 +                _type = "application";
    1.76 +                break;
    1.77 +            case MAILMIME_DISCRETE_TYPE_EXTENSION:
    1.78 +                _type = "extension";
    1.79 +                break;
    1.80 +            default:
    1.81 +                return NULL;
    1.82 +        }
    1.83 +
    1.84 +        len = strlen(_type) + 1 + strlen(content->ct_subtype) + 1;
    1.85 +        type = calloc(1, len);
    1.86 +        assert(type);
    1.87 +        // BUG: out of memory cannot be signaled
    1.88 +        if (type == NULL)
    1.89 +            return NULL;
    1.90 +
    1.91 +        strcpy(type, _type);
    1.92 +        strcat(type, "/");
    1.93 +        strcat(type, content->ct_subtype);
    1.94 +
    1.95 +        return type;
    1.96 +    }
    1.97 +
    1.98 +    return NULL;
    1.99 +}
   1.100 +