Write the messages to stdout
This commit is contained in:
parent
1945abfc2a
commit
fdc915cd66
2 changed files with 34 additions and 10 deletions
|
@ -29,11 +29,10 @@ fn main() {
|
|||
}
|
||||
}
|
||||
None => {
|
||||
let msg = Message::from_entry(&entry);
|
||||
if !entry.is_end_of_message() {
|
||||
let msg = Message::from_line(entry.get_data());
|
||||
messages.insert(msg_id, msg);
|
||||
} else {
|
||||
let msg = Message::new();
|
||||
msg.sign_and_return();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,27 @@
|
|||
use crate::entry::Entry;
|
||||
use std::io::{BufWriter, Write};
|
||||
|
||||
pub const RETURN_SEP: &[u8] = b"|";
|
||||
pub const RETURN_START: &[u8] = b"filter-dataline|";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Message {
|
||||
session_id: String,
|
||||
token: String,
|
||||
lines: Vec<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn new() -> Self {
|
||||
Self { lines: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn from_line(line: &[u8]) -> Self {
|
||||
Self {
|
||||
lines: vec![line.to_vec()],
|
||||
pub fn from_entry(entry: &Entry) -> Self {
|
||||
let mut ret = Self {
|
||||
session_id: entry.get_session_id().to_string(),
|
||||
token: entry.get_token().to_string(),
|
||||
lines: Vec::new(),
|
||||
};
|
||||
if !entry.is_end_of_message() {
|
||||
ret.append_line(entry.get_data());
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn append_line(&mut self, line: &[u8]) {
|
||||
|
@ -19,6 +29,21 @@ impl Message {
|
|||
}
|
||||
|
||||
pub fn sign_and_return(&self) {
|
||||
// TODO: sign the message using DKIM and send it to stdout
|
||||
// TODO: sign the message using DKIM
|
||||
for line in &self.lines {
|
||||
self.print_line(line);
|
||||
}
|
||||
self.print_line(b".");
|
||||
}
|
||||
|
||||
fn print_line(&self, line: &[u8]) {
|
||||
let mut stdout = BufWriter::new(std::io::stdout());
|
||||
stdout.write_all(RETURN_START).unwrap();
|
||||
stdout.write_all(self.session_id.as_bytes()).unwrap();
|
||||
stdout.write_all(RETURN_SEP).unwrap();
|
||||
stdout.write_all(self.token.as_bytes()).unwrap();
|
||||
stdout.write_all(RETURN_SEP).unwrap();
|
||||
stdout.write_all(line).unwrap();
|
||||
stdout.write_all(b"\n").unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue