* [sup-talk] [PATCH] Prettier printing of enclosed messages
@ 2009-05-29 12:48 Israel Herraiz
2009-06-05 15:36 ` William Morgan
0 siblings, 1 reply; 3+ messages in thread
From: Israel Herraiz @ 2009-05-29 12:48 UTC (permalink / raw)
Hi,
this patch prints enclosed messages with only some selected headers
instead of the full headers, just as "normal" messages.
Cheers,
Israel
---
lib/sup/message-chunks.rb | 26 +++++++++++++++++++-------
lib/sup/message.rb | 17 +++++++++++++----
2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
index 1bf7796..7b55c91 100644
--- a/lib/sup/message-chunks.rb
+++ b/lib/sup/message-chunks.rb
@@ -208,13 +208,25 @@ EOS
class EnclosedMessage
attr_reader :lines
- def initialize from, body
- @from = from
- @lines = body.split "\n"
- end
+ def initialize from, to, cc, date, subj
+ @from = from ? "unknown sender" : from.full_adress
+ @to = to ? "" : to.map { |p| p.full_address }.join(", ")
+ @cc = cc ? "" : cc.map { |p| p.full_address }.join(", ")
+ if date
+ @date = date.rfc822
+ else
+ @date = ""
+ end
- def from
- @from ? @from.longname : "unknown sender"
+ @subj = subj
+
+ @lines = "\nFrom: #{from}\n"
+ @lines += "To: #{to}\n"
+ if !cc.empty?
+ @lines += "Cc: #{cc}\n"
+ end
+ @lines += "Date: #{date}\n"
+ @lines += "Subject: #{subj}\n\n"
end
def inlineable?; false end
@@ -224,7 +236,7 @@ EOS
def viewable?; false end
def patina_color; :generic_notice_patina_color end
- def patina_text; "Begin enclosed message from #{from} (#{@lines.length} lines)" end
+ def patina_text; "Begin enclosed message sent on #{@date}" end
def color; :quote_color end
end
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 6dd1f7d..72ec6c5 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -383,10 +383,19 @@ private
chunks
elsif m.header.content_type == "message/rfc822"
payload = RMail::Parser.read(m.body)
- from = payload.header.from.first
- from_person = from ? Person.from_address(from.format) : nil
- [Chunk::EnclosedMessage.new(from_person, payload.to_s)] +
- message_to_chunks(payload, encrypted)
+ from = payload.header.from.first ? payload.header.from.first.format : ""
+ to = payload.header.to.map { |p| p.format }.join(", ")
+ cc = payload.header.cc.map { |p| p.format }.join(", ")
+ subj = payload.header.subject
+ subj = subj ? Message.normalize_subj(payload.header.subject.gsub(/\s+/, " ").gsub(/\s+$/, "")) : subj
+ if Rfc2047.is_encoded? subj
+ subj = Rfc2047.decode_to $encoding, subj
+ end
+ msgdate = payload.header.date
+ from_person = from ? Person.from_address (from) : nil
+ to_people = to ? Person.from_address_list (to) : nil
+ cc_people = cc ? Person.from_address_list (cc) : nil
+ [Chunk::EnclosedMessage.new(from_person, to_people, cc_people, msgdate, subj)] + message_to_chunks(payload, encrypted)
else
filename =
## first, paw through the headers looking for a filename
--
1.6.3.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [sup-talk] [PATCH] Prettier printing of enclosed messages
@ 2009-05-29 12:48 Israel Herraiz
0 siblings, 0 replies; 3+ messages in thread
From: Israel Herraiz @ 2009-05-29 12:48 UTC (permalink / raw)
Hi,
this patch prints enclosed messages with only some selected headers
instead of the full headers, just as "normal" messages.
Cheers,
Israel
---
lib/sup/message-chunks.rb | 26 +++++++++++++++++++-------
lib/sup/message.rb | 17 +++++++++++++----
2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
index 1bf7796..7b55c91 100644
--- a/lib/sup/message-chunks.rb
+++ b/lib/sup/message-chunks.rb
@@ -208,13 +208,25 @@ EOS
class EnclosedMessage
attr_reader :lines
- def initialize from, body
- @from = from
- @lines = body.split "\n"
- end
+ def initialize from, to, cc, date, subj
+ @from = from ? "unknown sender" : from.full_adress
+ @to = to ? "" : to.map { |p| p.full_address }.join(", ")
+ @cc = cc ? "" : cc.map { |p| p.full_address }.join(", ")
+ if date
+ @date = date.rfc822
+ else
+ @date = ""
+ end
- def from
- @from ? @from.longname : "unknown sender"
+ @subj = subj
+
+ @lines = "\nFrom: #{from}\n"
+ @lines += "To: #{to}\n"
+ if !cc.empty?
+ @lines += "Cc: #{cc}\n"
+ end
+ @lines += "Date: #{date}\n"
+ @lines += "Subject: #{subj}\n\n"
end
def inlineable?; false end
@@ -224,7 +236,7 @@ EOS
def viewable?; false end
def patina_color; :generic_notice_patina_color end
- def patina_text; "Begin enclosed message from #{from} (#{@lines.length} lines)" end
+ def patina_text; "Begin enclosed message sent on #{@date}" end
def color; :quote_color end
end
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 6dd1f7d..72ec6c5 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -383,10 +383,19 @@ private
chunks
elsif m.header.content_type == "message/rfc822"
payload = RMail::Parser.read(m.body)
- from = payload.header.from.first
- from_person = from ? Person.from_address(from.format) : nil
- [Chunk::EnclosedMessage.new(from_person, payload.to_s)] +
- message_to_chunks(payload, encrypted)
+ from = payload.header.from.first ? payload.header.from.first.format : ""
+ to = payload.header.to.map { |p| p.format }.join(", ")
+ cc = payload.header.cc.map { |p| p.format }.join(", ")
+ subj = payload.header.subject
+ subj = subj ? Message.normalize_subj(payload.header.subject.gsub(/\s+/, " ").gsub(/\s+$/, "")) : subj
+ if Rfc2047.is_encoded? subj
+ subj = Rfc2047.decode_to $encoding, subj
+ end
+ msgdate = payload.header.date
+ from_person = from ? Person.from_address (from) : nil
+ to_people = to ? Person.from_address_list (to) : nil
+ cc_people = cc ? Person.from_address_list (cc) : nil
+ [Chunk::EnclosedMessage.new(from_person, to_people, cc_people, msgdate, subj)] + message_to_chunks(payload, encrypted)
else
filename =
## first, paw through the headers looking for a filename
--
1.6.3.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-06-05 15:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-29 12:48 [sup-talk] [PATCH] Prettier printing of enclosed messages Israel Herraiz
2009-06-05 15:36 ` William Morgan
-- strict thread matches above, loose matches on Subject: below --
2009-05-29 12:48 Israel Herraiz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox