turn charset into a lua package as well.
[apps/madmutt.git] / charset.cpkg
similarity index 82%
rename from charset.c
rename to charset.cpkg
index 11441e4..3db2745 100644 (file)
--- a/charset.c
 #  include <langinfo.h>
 #endif
 
-#include "mutt.h"
 #include "charset.h"
 
 #ifndef EILSEQ
 #  define EILSEQ EINVAL
 #endif
+@import "lib-lua/base.cpkg"
+
+@package MCharset {
+    /*
+     ** .pp
+     ** This variable is a colon-separated list of character encoding
+     ** schemes for messages without character encoding indication.
+     ** Header field values and message body content without character encoding
+     ** indication would be assumed that they are written in one of this list.
+     ** By default, all the header fields and message body without any charset
+     ** indication are assumed to be in \fTus-ascii\fP.
+     ** .pp
+     ** For example, Japanese users might prefer this:
+     ** .pp
+     ** \fTset assumed_charset="iso-2022-jp:euc-jp:shift_jis:utf-8"\fP
+     ** .pp
+     ** However, only the first content is valid for the message body.
+     ** This variable is valid only if $$strict_mime is unset.
+     */
+    string_t assumed_charset = m_strdup("us-ascii");
+
+    /*
+     ** .pp
+     ** Character set your terminal uses to display and enter textual data.
+     */
+    string_t charset         = NULL;
+
+    /*
+     ** .pp
+     ** This variable is a colon-separated list of character encoding
+     ** schemes for text file attatchments.
+     ** If \fIunset\fP, $$charset value will be used instead.
+     ** For example, the following configuration would work for Japanese
+     ** text handling:
+     ** .pp
+     ** \fTset file_charset="iso-2022-jp:euc-jp:shift_jis:utf-8"\fP
+     ** .pp
+     ** Note: ``\fTiso-2022-*\fP'' must be put at the head of the value as shown above
+     ** if included.
+     */
+    string_t file_charset    = NULL;
+
+    /*
+     ** .pp
+     ** A list of character sets for outgoing messages. Madmutt will use the
+     ** first character set into which the text can be converted exactly.
+     ** If your ``$$charset'' is not \fTiso-8859-1\fP and recipients may not
+     ** understand \fTUTF-8\fP, it is advisable to include in the list an
+     ** appropriate widely used standard character set (such as
+     ** \fTiso-8859-2\fP, \fTkoi8-r\fP or \fTiso-2022-jp\fP) either
+     ** instead of or after \fTiso-8859-1\fP.
+     */
+    string_t send_charset    = m_strdup("us-ascii:iso-8859-1:utf-8");
+};
 
-char *Charset;
 int Charset_is_utf8 = 0;
 wchar_t CharsetReplacement = '?';
 
@@ -58,18 +110,18 @@ void charset_initialize(void)
 
     /* finally, set $charset */
     if (!m_strisempty(buff2)) {
-        m_strreplace(&Charset, buff2);
+        m_strreplace(&MCharset.charset, buff2);
     } else
 #endif
     {
-        m_strreplace(&Charset, "iso-8859-1");
+        m_strreplace(&MCharset.charset, "iso-8859-1");
     }
 
-    Charset_is_utf8    = !m_strcmp(Charset, "utf-8");
+    Charset_is_utf8    = !m_strcmp(MCharset.charset, "utf-8");
     CharsetReplacement = Charset_is_utf8 ? 0xfffd : '?';
 
 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
-    bind_textdomain_codeset(PACKAGE, Charset);
+    bind_textdomain_codeset(PACKAGE, MCharset.charset);
 #endif
 }
 
@@ -316,7 +368,7 @@ static ssize_t convert_string(const char *f, ssize_t flen,
 
 int mutt_convert_nonmime_string(char **ps)
 {
-    const char *p = AssumedCharset;
+    const char *p = MCharset.assumed_charset;
     ssize_t ulen = m_strlen(*ps);
     char *u = *ps;
 
@@ -335,7 +387,7 @@ int mutt_convert_nonmime_string(char **ps)
         m_strncpy(fromcode, sizeof(fromcode), p, q - p);
         p = q;
 
-        if (convert_string(u, ulen, fromcode, Charset, &s, &slen) >= 0) {
+        if (convert_string(u, ulen, fromcode, MCharset.charset, &s, &slen) >= 0) {
             p_delete(ps);
             *ps = s;
             return 0;
@@ -350,7 +402,7 @@ int mutt_convert_nonmime_string(char **ps)
 /****************************************************************************/
 
 /* fgetconv_t stuff for converting a file while reading it
-   Used in sendlib.c for converting from mutt's Charset */
+   Used in sendlib.c for converting from mutt's charset */
 
 struct fgetconv_t {
     FILE *file;
@@ -468,3 +520,5 @@ char *fgetconvs(char *buf, ssize_t len, fgetconv_t *fc)
 
     return pos ? buf : NULL;
 }
+
+/* vim:set ft=c: */