From: Thomas Jarosch Date: Thu, 16 Feb 2006 13:39:53 +0000 (+0000) Subject: ui, libi2ncommon: (tomj) email filtering: decode UTF-7 foldernames (#808) X-Git-Tag: v2.6~217 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=d116a071f0c5780ae8414c913b7637b3a9549996;p=libi2ncommon ui, libi2ncommon: (tomj) email filtering: decode UTF-7 foldernames (#808) --- diff --git a/aclocal.m4 b/aclocal.m4 index 478ae5f..273b9ea 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,4 +1,4 @@ -dnl ./aclocal.m4 generated automatically by aclocal 1.4-p5 +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation diff --git a/configure.in b/configure.in index 3ae3733..be74c6b 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ AC_INIT(configure.in) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(libi2ncommon, 0.1) +AM_INIT_AUTOMAKE(libi2ncommon, 0.2) AC_LANG_CPLUSPLUS AC_PROG_CXX @@ -25,6 +25,10 @@ PKG_CHECK_MODULES(LIBGETTEXT, libgettext >= 0.0.0) AC_SUBST(LIBGETTEXT_CFLAGS) AC_SUBST(LIBGETTEXT_LIBS) +PKG_CHECK_MODULES(LIBICONV, libiconv >= 0.0.0) +AC_SUBST(LIBICONV_CFLAGS) +AC_SUBST(LIBICONV_LIBS) + AM_PATH_CPPUNIT(1.8.0) AC_OUTPUT(Makefile src/Makefile libi2ncommon.pc test/Makefile) diff --git a/src/Makefile.am b/src/Makefile.am index 4273e63..1a698e6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ # set the include path found by configure -INCLUDES = -I$(top_srcdir)/src @LIBGETTEXT_CFLAGS@ $(all_includes) +INCLUDES = -I$(top_srcdir)/src @LIBGETTEXT_CFLAGS@ @LIBICONV_CFLAGS@ $(all_includes) # the library search path. lib_LTLIBRARIES = libi2ncommon.la @@ -11,4 +11,4 @@ libi2ncommon_la_SOURCES = oftmpstream.cpp ipfunc.cpp timefunc.cpp filefunc.cpp s # the library that is made has version (a-c).c.b. In this # example, the version is 2.1.2. (3:2:1) -libi2ncommon_la_LIBADD = @LIBGETTEXT_LIBS@ +libi2ncommon_la_LIBADD = @LIBGETTEXT_LIBS@ @LIBICONV_LIBS@ diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index 182dd26..dcc1cde 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -103,6 +103,36 @@ std::string iso_to_html(const std::string& isostring, bool showerr_bug) return result; } +std::string utf7imap_to_iso(const std::string& utf7imapstring) +{ + string result; + + iconv_t utf7imap2iso = iconv_open ("ISO-8859-1","UTF-7-IMAP"); + + if (utf7imap2iso == (iconv_t)-1) + throw runtime_error("iconv can't convert from UTF-7-IMAP to ISO-8859-1"); + + size_t in_size=utf7imapstring.size(); + size_t out_size=in_size; + + char *buf = (char *)malloc(out_size+1); + if (buf == NULL) + throw runtime_error("out of memory for iconv buffer"); + + const char *in = utf7imapstring.c_str(); + char *out = buf; + iconv (utf7imap2iso, &in, &in_size, &out, &out_size); + + buf[utf7imapstring.size()-out_size]=0; + + result=buf; + + free(buf); + iconv_close (utf7imap2iso); + + return result; +} + bool replace_all(string &base, const char *ist, const char *soll) { string i=ist; diff --git a/src/stringfunc.hxx b/src/stringfunc.hxx index cfdc482..d7c4c10 100644 --- a/src/stringfunc.hxx +++ b/src/stringfunc.hxx @@ -24,6 +24,8 @@ std::string iso_to_utf8(const std::string& isostring); std::string utf8_to_iso(const std::string& utf8string); std::string iso_to_html(const std::string& isostring, bool showerr_bug=false); +std::string utf7imap_to_iso(const std::string &utf7imapstring); + std::string escape(const std::string &s); std::string descape(const std::string &s, int startpos, int &endpos);