Commit
+19 -1 +/-1 browse
1 | diff --git a/src/rewrite.rs b/src/rewrite.rs |
2 | index 8f02ee0..3686ab2 100644 |
3 | --- a/src/rewrite.rs |
4 | +++ b/src/rewrite.rs |
5 | @@ -1,3 +1,4 @@ |
6 | + use mail_auth::common::headers::Writer; |
7 | use mail_parser::{HeaderName, Message, MessageParser}; |
8 | |
9 | /// Basically a hack that can modify messages expensively re-parsing them on |
10 | @@ -28,13 +29,30 @@ impl<'a> Rewrite<'a> { |
11 | .parser |
12 | .parse_headers(self.raw_message.as_slice()) |
13 | .expect("Cannot parse message"); |
14 | - if let Some(header) = message.headers().iter().find(|header| header.name() == key.as_str()) { |
15 | + if let Some(header) = message |
16 | + .headers() |
17 | + .iter() |
18 | + .find(|header| header.name() == key.as_str()) |
19 | + { |
20 | let (start, end) = (header.offset_field(), header.offset_end()); |
21 | self.raw_message.drain(start..end); |
22 | } |
23 | let header: Vec<u8> = format!("{}: {}\n", key, value.trim_end()).bytes().collect(); |
24 | self.raw_message.splice(0..0, header); |
25 | } |
26 | + |
27 | + pub fn prepend(&mut self, header: &Header) { |
28 | + self.raw_message.splice(0..0, header.0.clone()); |
29 | + } |
30 | + } |
31 | + |
32 | + #[derive(Default)] |
33 | + pub struct Header(Vec<u8>); |
34 | + |
35 | + impl Writer for Header { |
36 | + fn write(&mut self, buf: &[u8]) { |
37 | + self.0.write(buf); |
38 | + } |
39 | } |
40 | |
41 | #[cfg(test)] |