From: Helge Titlestad <helgedt@tihlde.org>
To: sup-talk <sup-talk@rubyforge.org>
Subject: [sup-talk] [PATCH] detect and set charset on text/* attachments
Date: Mon, 19 Oct 2009 16:07:26 +0200 [thread overview]
Message-ID: <1255961127-sup-3168@tihlde.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 536 bytes --]
I got some feedback from non-suppers that my utf-8 text attachments were
messed up. When I checked they (the MIME headers) lacked any info on charset,
which I believe should be set for text/*.
Here's a patch that uses the chardet gem to (try to) detect the appropriate charset
and sets it in the Content-Type header.
Can't guarantee its robustness - have only tried on a couple of text files and
one non-text file.
Please tell me if I should use some different way of sending patches... This git
flow is a bit new to me. (=
--
alge
[-- Attachment #2: 0001-Detect-charset-for-text-file-attachments.patch --]
[-- Type: application/octet-stream, Size: 1927 bytes --]
From 735a5ceb757599af71702d4ece8d29cb11f2c65b Mon Sep 17 00:00:00 2001
From: Helge Titlestad <helgedt@tihlde.org>
Date: Mon, 19 Oct 2009 16:03:56 +0200
Subject: [PATCH] Detect charset for text/* file attachments.
Adds dependency on chardet gem, and uses it to detect the charset.
---
README.txt | 1 +
Rakefile | 1 +
lib/sup/util.rb | 8 +++++++-
3 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/README.txt b/README.txt
index 4204270..3a98fa3 100644
--- a/README.txt
+++ b/README.txt
@@ -106,6 +106,7 @@ Current limitations which will be fixed:
- mime-types
- gettext
- fastthread
+ - chardet
== INSTALL:
diff --git a/Rakefile b/Rakefile
index 67cd0d2..3fb0d5e 100644
--- a/Rakefile
+++ b/Rakefile
@@ -57,6 +57,7 @@ spec = Gem::Specification.new do |s|
s.add_dependency "mime-types", "~> 1"
s.add_dependency "gettext"
s.add_dependency "fastthread"
+ s.add_dependency "chardet", ">= 0.9.0"
end
Rake::GemPackageTask.new(spec) do |pkg|
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index f99e1c1..ef7b892 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -3,6 +3,7 @@ require 'lockfile'
require 'mime/types'
require 'pathname'
require 'set'
+require 'UniversalDetector'
## time for some monkeypatching!
class Lockfile
@@ -71,8 +72,13 @@ module RMail
def self.make_attachment payload, mime_type, encoding, filename
a = Message.new
+
+ cs = UniversalDetector::chardet(payload)['encoding'] if mime_type =~ /^text\//i
+ ct = "#{mime_type}; name=#{filename.inspect}"
+ ct += "; charset=#{cs}" if cs
+
a.header.add "Content-Disposition", "attachment; filename=#{filename.inspect}"
- a.header.add "Content-Type", "#{mime_type}; name=#{filename.inspect}"
+ a.header.add "Content-Type", ct
a.header.add "Content-Transfer-Encoding", encoding if encoding
a.body =
case encoding
--
1.5.6.5
[-- Attachment #3: Type: text/plain, Size: 140 bytes --]
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk
next reply other threads:[~2009-10-19 18:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-19 14:07 Helge Titlestad [this message]
2009-11-03 17:16 ` William Morgan
2009-11-03 19:23 ` Helge Titlestad
2012-06-21 20:26 Helge Titlestad
2012-06-22 8:48 ` Gaute Hope
2012-06-22 10:29 ` Helge Titlestad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1255961127-sup-3168@tihlde.org \
--to=helgedt@tihlde.org \
--cc=sup-talk@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox