mail_core/resource/source.rs
1
2use headers::{
3 header_components::MediaType
4};
5use ::{
6 iri::IRI
7};
8
9#[cfg(feature="serde")]
10use serde::{Serialize, Deserialize};
11
12/// POD containing the IRI which should be used to laod a resource well as
13/// an optional file name to use and a description about how the content type
14/// should be handled.
15#[derive(Debug, Clone)]
16#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
17pub struct Source {
18
19 /// A International Resource Identifier pointing to a source
20 /// from which the Resource can be loaded. Note that the interpretation
21 /// of the IRI is left to the `ResourceLoader` implementation of the
22 /// context. The `ResourceLoader` can decide to reject valid IRI's e.g.
23 /// a (non local) http url is likely to be rejected by any implementation.
24 pub iri: IRI,
25
26 /// Allows specifying how the media type detection is done.
27 #[cfg_attr(feature="serde", serde(default))]
28 pub use_media_type: UseMediaType,
29
30 /// Allows providing a explicit name overriding any inferred name.
31 ///
32 /// If a resource if loaded from a IRI it potentially can contain
33 /// a inferred name e.g. for loading a file `secret_thing.png` it
34 /// would be just that file name, but you potentially want to provide
35 /// a name which differs from the name the file has in the file system
36 /// in which case you can provide a name here.
37 ///
38 /// Note that file names are optional and don't need to be provided at all.
39 /// But it is strongly recommended to provide them for anything used as
40 /// attachment but normally irrelevant for anything else.
41 #[cfg_attr(feature="serde", serde(default))]
42 pub use_file_name: Option<String>
43}
44
45/// Specifies how the content type should be handled when loading the data.
46///
47/// Depending on how the context implementation handles the loading it might
48/// already have a content type, but if not it might also need to "sniff" it,
49/// which can fail. Nevertheless how any of the aspects are handled in detail
50/// depends on the context implementation.
51///
52#[derive(Debug, Clone)]
53#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
54pub enum UseMediaType {
55 /// Sniff content type if no content type was given from any other place.
56 Auto,
57
58 /// Use this content type if no content type was given from any other place.
59 ///
60 /// As resources are loaded by IRI they could be loaded from any place and
61 /// this place could be storing the data with the right content type, in which
62 /// case that content type should be used.
63 Default(MediaType),
64
65 // /// Always use this content type even if it is known to have a different content type.
66 // Override(MediaType)
67}
68
69impl Default for UseMediaType {
70 fn default() -> Self {
71 UseMediaType::Auto
72 }
73}