-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_printer.cpp
More file actions
58 lines (48 loc) · 1.35 KB
/
message_printer.cpp
File metadata and controls
58 lines (48 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "message_printer.hpp"
#include <iostream>
using namespace Compose;
class HeaderPrinter {
std::ostream &m_os;
public:
explicit HeaderPrinter(std::ostream &os)
: m_os(os)
{}
void operator ()(const Gtk::TreeModel::iterator &i) {
Gtk::TreeRow row = *i;
int pos = 0;
Glib::ustring name = row[header_model().m_name];
m_os << name << ":";
pos += name.length() + 1;
Glib::ustring value = row[header_model().m_value];
Glib::ustring::size_type start;
Glib::ustring::size_type end = 0;
do {
start = value.find_first_not_of(" \t", end);
if (start > value.length()) // OMGWTFBBQ
start = value.length();
end = value.find_first_of(" \t", start);
if (end > value.length()) // OMGWTFBBQ
end = value.length();
if (end - start == 0)
continue;
if (pos + (end - start) + 1 > 78) {
m_os << std::endl;
pos = 0;
}
m_os << " " << value.substr(start, end - start);
pos += (end - start) + 1;
} while (end < value.length());
m_os << std::endl;
}
};
std::ostream &Compose::operator <<(std::ostream &os, Glib::RefPtr<Message> message) {
HeaderPrinter header_printer(os);
Gtk::TreeModel::iterator i = message->m_ref_headers->get_iter("0");
while (i) {
header_printer(i);
++i;
}
os << std::endl;
os << message->m_ref_body_buffer->get_text();
return os;
}