1/* Copyright 2016 Software Freedom Conservancy Inc.
2 *
3 * This software is licensed under the GNU Lesser General Public License
4 * (version 2.1 or later).  See the COPYING file in this distribution.
5 */
6
7/**
8 * A representation of the RFC 2183 Content-Disposition field.
9 *
10 * See [[https://tools.ietf.org/html/rfc2183]]
11 */
12
13public class Geary.Mime.ContentDisposition : Geary.BaseObject {
14    /**
15     * Filename parameter name.
16     *
17     * See [[https://tools.ietf.org/html/rfc2183#section-2.3]]
18     */
19    public const string FILENAME = "filename";
20
21    /**
22     * Creation-Date parameter name.
23     *
24     * See [[https://tools.ietf.org/html/rfc2183#section-2.4]]
25     */
26    public const string CREATION_DATE = "creation-date";
27
28    /**
29     * Modification-Date parameter name.
30     *
31     * See [[https://tools.ietf.org/html/rfc2183#section-2.5]]
32     */
33    public const string MODIFICATION_DATE = "modification-date";
34
35    /**
36     * Read-Date parameter name.
37     *
38     * See [[https://tools.ietf.org/html/rfc2183#section-2.6]]
39     */
40    public const string READ_DATE = "read-date";
41
42    /**
43     * Size parameter name.
44     *
45     * See [[https://tools.ietf.org/html/rfc2183#section-2.7]]
46     */
47    public const string SIZE = "size";
48
49    /**
50     * The {@link DispositionType}, which is {@link DispositionType.UNSPECIFIED} if not specified.
51     */
52    public DispositionType disposition_type { get; private set; }
53
54    /**
55     * True if the original DispositionType was unknown.
56     */
57    public bool is_unknown_disposition_type { get; private set; }
58
59    /**
60     * The original disposition type string.
61     */
62    public string? original_disposition_type_string { get; private set; }
63
64    /**
65     * Various parameters associated with the content's disposition.
66     *
67     * This is never null.  Rather, an empty ContentParameters is held if the Content-Type has
68     * no parameters.
69     *
70     * @see FILENAME
71     * @see CREATION_DATE
72     * @see MODIFICATION_DATE
73     * @see READ_DATE
74     * @see SIZE
75     */
76    public ContentParameters params { get; private set; }
77
78    /**
79     * Create a Content-Disposition representation
80     */
81    public ContentDisposition(string? disposition, ContentParameters? params) {
82        bool is_unknown;
83        disposition_type = DispositionType.deserialize(disposition, out is_unknown);
84        is_unknown_disposition_type = is_unknown;
85        original_disposition_type_string = disposition;
86        this.params = params ?? new ContentParameters();
87    }
88
89    /**
90     * Create a simplified Content-Disposition representation.
91     */
92    public ContentDisposition.simple(DispositionType disposition_type) {
93        this.disposition_type = disposition_type;
94        is_unknown_disposition_type = false;
95        original_disposition_type_string = null;
96        this.params = new ContentParameters();
97    }
98
99    internal ContentDisposition.from_gmime(GMime.ContentDisposition content_disposition) {
100        bool is_unknown;
101        disposition_type = DispositionType.deserialize(content_disposition.get_disposition(),
102            out is_unknown);
103        is_unknown_disposition_type = is_unknown;
104        original_disposition_type_string = content_disposition.get_disposition();
105        params = new ContentParameters.from_gmime(content_disposition.get_parameters());
106    }
107}
108
109