Browse Source

melib: remove control characters from subject

tags/alpha-0.4.1
Manos Pitsidianakis 2 years ago
parent
commit
46a807eee1
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 10
      melib/src/email.rs
  2. 32
      ui/src/components/mail/view.rs
  3. 36
      ui/src/terminal/cells.rs

10
melib/src/email.rs

@ -467,7 +467,15 @@ impl Envelope {
};
self.in_reply_to = Some(MessageID::new(new_val, slice));
}
pub fn set_subject(&mut self, new_val: Vec<u8>) {
pub fn set_subject(&mut self, mut new_val: Vec<u8>) {
while new_val
.last()
.map(|&u| char::is_control(u as char))
.unwrap_or(false)
{
new_val.pop();
}
self.subject = Some(new_val);
}
pub fn set_message_id(&mut self, new_val: &[u8]) {

32
ui/src/components/mail/view.rs

@ -265,38 +265,6 @@ impl MailView {
}
}
}
pub fn plain_text_to_buf(s: &str, highlight_urls: bool) -> CellBuffer {
let mut buf = CellBuffer::from(s);
if highlight_urls {
let lines: Vec<&str> = s.split('\n').map(|l| l.trim_end()).collect();
let mut shift = 0;
let mut lidx_total = 0;
let finder = LinkFinder::new();
for r in &lines {
for l in finder.links(&r) {
let offset = if lidx_total < 10 {
3
} else if lidx_total < 100 {
4
} else if lidx_total < 1000 {
5
} else {
panic!("BUG: Message body with more than 100 urls");
};
for i in 1..=offset {
buf[(l.start() + shift - i, 0)].set_fg(Color::Byte(226));
//buf[(l.start() + shift - 2, 0)].set_fg(Color::Byte(226));
//buf[(l.start() + shift - 3, 0)].set_fg(Color::Byte(226));
}
lidx_total += 1;
}
// Each Cell represents one char so next line will be:
shift += r.chars().count() + 1;
}
}
buf
}
pub fn update(&mut self, new_coordinates: (usize, usize, EnvelopeHash)) {
self.coordinates = new_coordinates;

36
ui/src/terminal/cells.rs

@ -138,24 +138,6 @@ impl CellBuffer {
self.rows = newrows;
}
pub fn split_newlines(self) -> Self {
let lines: Vec<&[Cell]> = self.split(|cell| cell.ch() == '\n').collect();
let height = lines.len();
let width = lines.iter().map(|l| l.len()).max().unwrap_or(0) + 1;
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
{
let mut x;
let c_slice: &mut [Cell] = &mut content;
for (y, l) in lines.iter().enumerate() {
let y_r = y * width;
x = l.len() + y_r;
c_slice[y_r..x].copy_from_slice(l);
c_slice[x].set_ch('\n');
}
}
content
}
pub fn is_empty(&self) -> bool {
self.buf.is_empty()
}
@ -422,24 +404,6 @@ impl Default for CellBuffer {
}
}
impl<'a> From<&'a str> for CellBuffer {
fn from(s: &'a str) -> Self {
let lines: Vec<&str> = s.lines().map(|l| l.trim_end()).collect();
let len = s.len() + lines.len();
let mut buf = CellBuffer::new(len, 1, Cell::default());
let mut x = 0;
for l in &lines {
for (idx, c) in l.chars().enumerate() {
buf[(x + idx, 0)].set_ch(c);
}
x += l.chars().count();
buf[(x, 0)].set_ch('\n');
x += 1;
}
buf
}
}
impl fmt::Display for CellBuffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
'_y: for y in 0..self.rows {

Loading…
Cancel
Save