1use std::collections::HashMap;
2
3pub const HASHSIZE: usize = 673;
4pub const MAXLINE: usize = 1024;
5pub const NAMESTRLEN: usize = 80;
6pub const MAILSTRLEN: usize = 80;
7pub const DATESTRLEN: usize = 80;
8pub const SUBJSTRLEN: usize = 256;
9pub const URLSTRLEN: usize = 256;
10
11pub const BASEYEAR: i32 = 1970;
12
13pub const PROGNAME: &str = "hypermail";
14pub const HMURL: &str = "http://www.hypermail-project.org/";
15pub const INDEXNAME: &str = "index";
16pub const DIRNAME: &str = "archive";
17
18pub const NONAME: &str = "(no name)";
19pub const NODATE: &str = "(no date)";
20pub const NOEMAIL: &str = "(no email)";
21pub const NOSUBJECT: &str = "(no subject)";
22
23pub const GDBM_INDEX_NAME: &str = ".hm2index";
24pub const HAOF_NAME: &str = "archive_overview.haof";
25
26pub const FILE_SUFFIXER: &str = "part";
27pub const DIR_PREFIXER: &str = "att-";
28pub const REPLACEMENT_CHAR: char = '_';
29pub const META_DIR: &str = ".meta";
30pub const META_EXTENSION: &str = ".meta";
31
32pub const PATH_SEPARATOR: char = '/';
33
34pub const PAGE_TOP: i32 = 1;
35pub const PAGE_BOTTOM: i32 = 2;
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38pub enum IndexType {
39 Date,
40 Thread,
41 Subject,
42 Author,
43 Attachment,
44 Folders,
45 NoIndex,
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49pub enum FilteredReason {
50 Delete = 1,
51 Expire = 2,
52 FilteredOut = 4,
53 FilteredRequired = 8,
54 FilteredOld = 16,
55 FilteredNew = 32,
56}
57
58#[derive(Debug, Clone)]
59pub struct Push {
60 pub string: String,
61}
62
63impl Default for Push {
64 fn default() -> Self {
65 Self::new()
66 }
67}
68
69impl Push {
70 pub fn new() -> Self {
71 Push { string: String::new() }
72 }
73
74 pub fn push_byte(&mut self, b: u8) {
75 self.string.push(b as char);
76 }
77
78 pub fn push_str(&mut self, s: &str) {
79 self.string.push_str(s);
80 }
81
82 pub fn push_nstring(&mut self, s: &str, n: usize) {
83 let mut len = s.len().min(n);
84 while !s.is_char_boundary(len) {
85 len -= 1;
86 }
87 self.string.push_str(&s[..len]);
88 }
89
90 pub fn len(&self) -> usize {
91 self.string.len()
92 }
93
94 pub fn is_empty(&self) -> bool {
95 self.string.is_empty()
96 }
97
98 pub fn as_str(&self) -> &str {
99 &self.string
100 }
101
102 pub fn into_string(self) -> String {
103 self.string
104 }
105}
106
107#[derive(Debug, Clone)]
108pub struct Body {
109 pub line: String,
110 pub converted: bool,
112 pub html: bool,
113 pub header: bool,
114 pub parsed_header: bool,
115 pub attached: bool,
116 pub demimed: bool,
117 pub msgnum: i32,
118}
119
120#[derive(Debug, Clone)]
121pub struct BodyChain {
122 pub bodies: Vec<Body>,
123}
124
125#[derive(Debug, Clone)]
126pub struct Reply {
127 pub from_msgnum: i32,
128 pub msgnum: i32,
129 pub data: Option<usize>,
130 pub maybe_reply: i32,
131}
132
133#[derive(Debug, Clone)]
134pub struct HmList {
135 pub values: Vec<String>,
136}
137
138#[derive(Debug, Clone)]
139pub struct HashEmail {
140 pub email_index: usize,
141}
142
143#[derive(Debug, Clone)]
144pub struct EmailSubdir {
145 pub first_email: Option<usize>,
146 pub last_email: Option<usize>,
147 pub subdir: String,
148 pub full_path: String,
149 pub rel_path_to_top: String,
150 pub count: i32,
151 pub description: Option<String>,
152 pub a_date: i64,
153}
154
155#[derive(Debug, Clone)]
156pub struct EmailInfo {
157 pub msgnum: i32,
158 pub name: Option<String>,
159 pub email_addr: Option<String>,
160 pub from_date_str: Option<String>,
161 pub from_date: i64,
162 pub date_str: Option<String>,
163 pub date: i64,
164 pub msgid: Option<String>,
165 pub subject: Option<String>,
166 pub unre_subject: Option<String>,
167 pub inreplyto: Option<String>,
168 pub charset: Option<String>,
169 pub datenum: i64,
170 pub flags: i32,
171 pub initial_next_in_thread: i32,
172 pub bodylist: BodyChain,
173 pub replylist: Vec<Reply>,
174 pub is_reply: bool,
175 pub subdir: Option<usize>,
176 pub exp_time: i64,
177 pub is_deleted: i32,
178 pub deletion_completed: i32,
179}
180
181impl Default for EmailInfo {
182 fn default() -> Self {
183 EmailInfo {
184 msgnum: 0,
185 name: None,
186 email_addr: None,
187 from_date_str: None,
188 from_date: 0,
189 date_str: None,
190 date: 0,
191 msgid: None,
192 subject: None,
193 unre_subject: None,
194 inreplyto: None,
195 charset: None,
196 datenum: 0,
197 flags: 0,
198 initial_next_in_thread: 0,
199 bodylist: BodyChain { bodies: Vec::new() },
200 replylist: Vec::new(),
201 is_reply: false,
202 subdir: None,
203 exp_time: 0,
204 is_deleted: 0,
205 deletion_completed: 0,
206 }
207 }
208}
209
210#[derive(Debug, Clone)]
211pub struct Header {
212 pub email_index: usize,
213 pub left: Option<Box<Header>>,
214 pub right: Option<Box<Header>>,
215}
216
217impl Drop for Header {
225 fn drop(&mut self) {
226 let mut stack: Vec<Box<Header>> = Vec::new();
227 if let Some(l) = self.left.take() {
228 stack.push(l);
229 }
230 if let Some(r) = self.right.take() {
231 stack.push(r);
232 }
233 while let Some(mut node) = stack.pop() {
234 if let Some(l) = node.left.take() {
235 stack.push(l);
236 }
237 if let Some(r) = node.right.take() {
238 stack.push(r);
239 }
240 }
242 }
243}
244
245#[derive(Debug, Clone)]
246pub struct Attachment {
247 pub content_type: String,
248 pub name: Option<String>,
249 pub id: Option<String>,
250 pub stored_as: Option<String>,
251 pub descr: Option<String>,
252}
253
254#[derive(Debug, Clone)]
255pub struct AttachmentItem {
256 pub attachment: Attachment,
257}
258
259#[derive(Debug, Clone, Default)]
260pub struct ArchiveState {
261 pub emails: Vec<EmailInfo>,
262 pub subject_list: Option<Box<Header>>,
263 pub author_list: Option<Box<Header>>,
264 pub date_list: Option<Box<Header>>,
265 pub deleted_list: Vec<usize>,
266 pub reply_list: Vec<Reply>,
267 pub thread_list: Vec<Reply>,
268 pub etable: HashMap<String, Vec<usize>>,
269 pub msgid_table: HashMap<String, usize>,
270 pub folders: Vec<EmailSubdir>,
271 pub max_msgnum: i32,
272}
273
274#[cfg(test)]
275mod tests {
276 use super::*;
277
278 #[test]
279 fn test_push_nstring_respects_char_boundary() {
280 let mut p = Push::new();
281 p.push_nstring("é", 1);
282 assert_eq!(p.string, "");
283 p.push_nstring("aé", 3);
284 assert_eq!(p.string, "aé");
285 }
286}