Difference between revisions of "Iconv (filter)"
From Mailutils
Jump to navigationJump to searchm |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | The <tt>iconv</tt> [[filter]] | + | The <tt>iconv</tt> [[filter]] converts between two charsets. It operates the same way in both [[MU_FILTER_DECODE|decode]] and [[MU_FILTER_ENCODE|encode]] modes. On initialization, it takes two mandatory arguments: |
* The name of the input charset | * The name of the input charset | ||
Line 17: | Line 17: | ||
The following example creates a <tt>iconv</tt> filter for converting from [http://en.wikipedia.org/wiki/iso-8859-2 iso-8859-2] to [http://en.wikipedia.org/wiki/utf-8 utf-8], signalling an error on the first conversion error: | The following example creates a <tt>iconv</tt> filter for converting from [http://en.wikipedia.org/wiki/iso-8859-2 iso-8859-2] to [http://en.wikipedia.org/wiki/utf-8 utf-8], signalling an error on the first conversion error: | ||
− | < | + | <syntaxhighlight lang="C"> |
int rc; /* Return code */ | int rc; /* Return code */ | ||
mu_stream_t flt; /* Filter stream */ | mu_stream_t flt; /* Filter stream */ | ||
− | char *argv[] = { "iso-8859-2", "utf-8", "none", NULL }; | + | char *argv[] = { "iconv", "iso-8859-2", "utf-8", "none", NULL }; |
− | rc = mu_filter_chain_create (&flt, input, MU_FILTER_ENCODE, MU_STREAM_READ, | + | rc = mu_filter_chain_create (&flt, input, MU_FILTER_ENCODE, MU_STREAM_READ, 4, argv); |
− | </ | + | </syntaxhighlight> |
Latest revision as of 13:23, 16 October 2023
The iconv filter converts between two charsets. It operates the same way in both decode and encode modes. On initialization, it takes two mandatory arguments:
- The name of the input charset
- The name of the output charset
Optional third argument specifies what to do when an illegal character sequence is encountered in the input stream. Its possible values are:
- none
- Return failure and stop further conversion.
- copy-pass
- Copy the offending octet to the output verbatim and continue conversion from the next octet.
- copy-octal
- Print the offending octet to the output using C octal conversion and continue conversion from the next octet.
The default is copy-octal unless previously overridden by a call to mu_default_fallback_mode function.
The following example creates a iconv filter for converting from iso-8859-2 to utf-8, signalling an error on the first conversion error:
int rc; /* Return code */
mu_stream_t flt; /* Filter stream */
char *argv[] = { "iconv", "iso-8859-2", "utf-8", "none", NULL };
rc = mu_filter_chain_create (&flt, input, MU_FILTER_ENCODE, MU_STREAM_READ, 4, argv);