imap_bodystructure/lib.rs
1//! # IMAP protocol library only related to BODYSTRUCTURE
2//!
3//! ### Examples
4//! Extract BODYSTRUCTURE
5//! ```rust
6//! # use imap_bodystructure::extractor;
7//! # use imap_bodystructure::parser::*;
8//! # fn main() {
9//! let text = br#"* 50000 FETCH (BODYSTRUCTURE ("TEXT" "PLAIN" ("CHARSET" "utf-8") NIL NIL "8BIT" 393 9 NIL NIL NIL))"#.to_vec();
10//! let bodystructure_text = extractor::extract_bodystructure(&text);
11//! assert_eq!(bodystructure_text, br#"BODYSTRUCTURE ("TEXT" "PLAIN" ("CHARSET" "utf-8") NIL NIL "8BIT" 393 9 NIL NIL NIL)"#.to_vec());
12//! let body_text_within_parentheses = head_bodystructure(&bodystructure_text).unwrap().0;
13//! assert_eq!(body_text_within_parentheses, br#"("TEXT" "PLAIN" ("CHARSET" "utf-8") NIL NIL "8BIT" 393 9 NIL NIL NIL)"#.as_ref());
14//! let body_tmp = Body::Single(SingleBody {
15//! content_type: ContentTypeHeaderField {
16//! ttype: ContentTypeTypeAndSubType {
17//! ttype: b"TEXT".to_vec(),
18//! subtype: b"PLAIN".to_vec()
19//! },
20//! parameters: Parameters {
21//! list: vec![Parameter {
22//! attribute: b"CHARSET".to_vec(),
23//! value: b"utf-8".to_vec()
24//! }]
25//! }
26//! },
27//! content_id: ContentIDHeaderField {
28//! value: None
29//! },
30//! content_description: ContentDescriptionHeaderField { value: None },
31//! content_transfer_encoding: ContentTransferEncodingHeaderField {
32//! value: b"8BIT".to_vec()
33//! },
34//! content_size: ContentSize(Some(393), Some(9)),
35//! content_md5: ContentMD5HeaderField {
36//! value: None
37//! },
38//! content_disposition: ContentDispositionHeaderField {
39//! value: None,
40//! parameters: Parameters { list: vec![
41//! ] }
42//! },
43//! content_language: ContentLanguageHeaderField { value: None },
44//! content_location: ContentLocationHeaderField { value: None },
45//! data: vec![],
46//! raw_header: vec![],
47//! });
48//! assert_eq!(body_parser(body_text_within_parentheses).unwrap().1, body_tmp);
49//! # }
50//! ```
51//! If you want to extract BODYSTRUCT with uid, you can use find_all_bodystructure_with_uid
52//! ```rust
53//! # use imap_bodystructure::response::find_all_bodystructure_with_uid;
54//! # use imap_bodystructure::parser::*;
55//! # use std::collections::HashMap;
56//!
57//! let mut text = b"* 154 FETCH (UID 649 FLAGS () RFC822.SIZE 2394 INTERNALDATE \"05-Dec-2023 06:16:58 +0000\" BODYSTRUCTURE ((\"text\" \"html\" (\"charset\" \"utf-8\") NIL NIL \"base64\" 1188 16 NIL NIL NIL NIL) \"mixed\" (\"boundary\" \"===============1522363357941492443==\") NIL NIL NIL) BODY[HEADER.FIELDS (DATE SUBJECT FROM SENDER REPLY-TO TO CC BCC MESSAGE-ID REFERENCES IN-REPLY-TO X-MAILMASTER-SHOWONERCPT X-CUSTOM-MAIL-MASTER-SENT-ID DISPOSITION-NOTIFICATION-TO X-CM-CTRLMSGS)] {181}\r\nSubject: =?utf-8?b?5L2g5aW9IDBiMGZiYjZkYmFmM2FmYmIgenFhLWVtYWls5rWL6K+V?=\r\nFrom: liutianyu@nextcloud.games\r\nTo: shenzongxu@nextcloud.games\r\nDate: Tue, 05 Dec 2023 06:16:58 -0000\r\n\r\n)\r\n".to_vec();
58//! let r = find_all_bodystructure_with_uid(&mut text, true).unwrap();
59//! let mut h: HashMap<Vec<u8>, Body> = HashMap::new();
60//! h.insert(
61//! b"649".to_vec(),
62//! Body::Multi(MultiBody {
63//! parts: vec![Body::Single(SingleBody {
64//! content_type: ContentTypeHeaderField {
65//! ttype: ContentTypeTypeAndSubType {
66//! ttype: b"text".to_vec(),
67//! subtype: b"html".to_vec(),
68//! },
69//! parameters: Parameters {
70//! list: vec![Parameter {
71//! attribute: b"charset".to_vec(),
72//! value: b"utf-8".to_vec(),
73//! }],
74//! },
75//! },
76//! content_id: ContentIDHeaderField { value: None },
77//! content_description: ContentDescriptionHeaderField { value: None },
78//! content_transfer_encoding: ContentTransferEncodingHeaderField {
79//! value: b"base64".to_vec(),
80//! },
81//! content_size: ContentSize(Some(1188), Some(16)),
82//! content_md5: ContentMD5HeaderField { value: None },
83//! content_disposition: ContentDispositionHeaderField {
84//! value: None,
85//! parameters: Parameters { list: vec![] },
86//! },
87//! content_language: ContentLanguageHeaderField { value: None },
88//! content_location: ContentLocationHeaderField { value: None },
89//! data: vec![],
90//! raw_header: vec![],
91//! })],
92//! content_type: b"mixed".to_vec(),
93//! parameters: Parameters {
94//! list: vec![Parameter {
95//! attribute: b"boundary".to_vec(),
96//! value: b"===============1522363357941492443==".to_vec(),
97//! }],
98//! },
99//! raw_header: b"Subject: =?utf-8?b?5L2g5aW9IDBiMGZiYjZkYmFmM2FmYmIgenFhLWVtYWls5rWL6K+V?=\r\nFrom: liutianyu@nextcloud.games\r\nTo: shenzongxu@nextcloud.games\r\nDate: Tue, 05 Dec 2023 06:16:58 -0000\r\nMIME-Version: 1.0\r\n".to_vec(),
100//! }),
101//! );
102//! assert_eq!(r, (b"".as_ref(), h));
103//! ```
104
105pub mod parser;
106// Get new SequenceNumbers
107pub mod sequence;
108pub mod extractor;
109pub mod response;