Commit
Author: Kevin Schoon [me@kevinschoon.com]
Hash: fdcc9074695b1bbb0dd23940d787c61d2447c982
Timestamp: Thu, 16 Jan 2025 21:09:08 +0000 (5 days ago)

+19 -1 +/-1 browse
add header to rewrite module
1diff --git a/src/rewrite.rs b/src/rewrite.rs
2index 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)]