diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 | 
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /libmail/rfc2047decode.C | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'libmail/rfc2047decode.C')
| -rw-r--r-- | libmail/rfc2047decode.C | 80 | 
1 files changed, 80 insertions, 0 deletions
| diff --git a/libmail/rfc2047decode.C b/libmail/rfc2047decode.C new file mode 100644 index 0000000..2853a9b --- /dev/null +++ b/libmail/rfc2047decode.C @@ -0,0 +1,80 @@ +/* +** Copyright 2002-2008, Double Precision Inc. +** +** See COPYING for distribution information. +*/ +#include "libmail_config.h" +#include "rfc2047decode.H" +#include "rfc822/rfc822.h" +#include "rfc822/rfc2047.h" +#include "mail.H" +#include <cstring> + +using namespace std; + +mail::rfc2047::decoder::decoder() +{ +} + +mail::rfc2047::decoder::~decoder() +{ +} + +void mail::rfc2047::decoder::rfc2047_decode_callback(const char *text, +						    size_t text_len, +						    void *voidarg) +{ +	((mail::rfc2047::decoder *)voidarg)->rfc2047_callback(text, text_len); +} + +void mail::rfc2047::decoder::rfc2047_callback(const char *text, size_t text_len) +{ +	decodedbuf.append(text, text+text_len); +} + +string mail::rfc2047::decoder::decode(string text, string charset) +{ +	decodedbuf.clear(); + +	if (rfc822_display_hdrvalue("subject", +				    text.c_str(), +				    charset.c_str(), +				    &mail::rfc2047::decoder:: +				    rfc2047_decode_callback, +				    NULL, +				    this) < 0) +		return text; + +	return decodedbuf; +} + +void mail::rfc2047::decoder::decode(vector<mail::address> &addr_cpy, +				    std::string charset) +{ +	vector<mail::address>::iterator b=addr_cpy.begin(), e=addr_cpy.end(); + +	while (b != e) +	{ +		b->setName(decode(b->getName(), charset)); +		b++; +	} +} + +string mail::rfc2047::decoder::decodeSimple(string str) +{ +	std::string output; + +	if (rfc2047_decoder(str.c_str(), &decodeSimpleCallback, &output) < 0) +		return str; + +	return output; +} + +void mail::rfc2047::decoder::decodeSimpleCallback(const char *chset, +						  const char *lang, +						  const char *content, +						  size_t cnt, +						  void *dummy) +{ +	((std::string *)dummy)->append(content, content+cnt); +} | 
