-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement decoding charsets (other than ascii and utf-8) while readin…
…g textual message parts, and improve search message.Part now has a ReaderUTF8OrBinary() along with the existing Reader(). the new function returns a reader of decoded content. we now use it in a few places, including search. we only support the charsets in golang.org/x/text/encoding/ianaindex. search has also been changed to not read the entire message in memory. instead, we make one 8k buffer for reading and search in that, and we keep the buffer around for all messages. saves quite some allocations when searching large mailboxes.
- Loading branch information
Showing
34 changed files
with
157,887 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package moxio | ||
|
||
import ( | ||
"io" | ||
"strings" | ||
|
||
"golang.org/x/text/encoding/ianaindex" | ||
) | ||
|
||
// DecodeReader returns a reader that reads from r, decoding as charset. If | ||
// charset is empty, us-ascii, utf-8 or unknown, the original reader is | ||
// returned and no decoding takes place. | ||
func DecodeReader(charset string, r io.Reader) io.Reader { | ||
switch strings.ToLower(charset) { | ||
case "", "us-ascii", "utf-8": | ||
return r | ||
} | ||
enc, _ := ianaindex.MIME.Encoding(charset) | ||
if enc == nil { | ||
enc, _ = ianaindex.IANA.Encoding(charset) | ||
} | ||
// todo: ianaindex doesn't know all encodings, e.g. gb2312. should we transform them, with which code? | ||
if enc == nil { | ||
return r | ||
} | ||
return enc.NewDecoder().Reader(r) | ||
} |
Oops, something went wrong.