Difference between revisions of "Base64 (filter)"

From Mailutils
Jump to navigationJump to search
m
m
 
Line 7: Line 7:
 
These filters are described by the following objects (declared in <tt>mailutils/filter.h</tt>):
 
These filters are described by the following objects (declared in <tt>mailutils/filter.h</tt>):
  
<source lang="C">
+
<syntaxhighlight lang="C">
 
extern mu_filter_record_t mu_base64_filter;
 
extern mu_filter_record_t mu_base64_filter;
 
extern mu_filter_record_t mu_rfc_2047_B_filter;
 
extern mu_filter_record_t mu_rfc_2047_B_filter;
</source>
+
</syntaxhighlight>
 
   
 
   
 
The following example illustrates how to create a read-only filter for encoding the input stream in standard ''base64'' form, with output file length limited to 76 octets:
 
The following example illustrates how to create a read-only filter for encoding the input stream in standard ''base64'' form, with output file length limited to 76 octets:
  
<source lang="C">
+
<syntaxhighlight lang="C">
 
   int rc;          /* Return code */
 
   int rc;          /* Return code */
 
   mu_stream_t flt; /* Filter stream */
 
   mu_stream_t flt; /* Filter stream */
  
 
   rc = mu_filter_create (&flt, input, "base64", MU_FILTER_ENCODE, MU_STREAM_READ);
 
   rc = mu_filter_create (&flt, input, "base64", MU_FILTER_ENCODE, MU_STREAM_READ);
</source>
+
</syntaxhighlight>
  
 
It is supposed that <tt>input</tt> is an object of type <tt>mu_stream_t</tt>, initialized previously.
 
It is supposed that <tt>input</tt> is an object of type <tt>mu_stream_t</tt>, initialized previously.
Line 25: Line 25:
 
For the sake of completeness, the same effect can be achieved (with a slight loss in performance), by creating the following [[filter chain]]: <tt>"B + linelen 76"</tt>.  This approach is illustrated in the example below:
 
For the sake of completeness, the same effect can be achieved (with a slight loss in performance), by creating the following [[filter chain]]: <tt>"B + linelen 76"</tt>.  This approach is illustrated in the example below:
  
<source lang="C">
+
<syntaxhighlight lang="C">
 
   int rc;          /* Return code */
 
   int rc;          /* Return code */
 
   mu_stream_t flt; /* Filter stream */
 
   mu_stream_t flt; /* Filter stream */
Line 31: Line 31:
  
 
   rc = mu_filter_chain_create (&flt, input, MU_FILTER_ENCODE, MU_STREAM_READ, 4, argv);
 
   rc = mu_filter_chain_create (&flt, input, MU_FILTER_ENCODE, MU_STREAM_READ, 4, argv);
</source>
+
</syntaxhighlight>
  
 
== See also ==
 
== See also ==

Latest revision as of 13:20, 16 October 2023

The base64 and B filters encode or decode the input using the base64 encoding.

The only difference between the two filters is that base64 in encode mode limits each ouput line length to 76 octets, whereas B produces a contiguous stream of base64 data.

In decode mode, both filters operate exactly the same way.

These filters are described by the following objects (declared in mailutils/filter.h):

extern mu_filter_record_t mu_base64_filter;
extern mu_filter_record_t mu_rfc_2047_B_filter;

The following example illustrates how to create a read-only filter for encoding the input stream in standard base64 form, with output file length limited to 76 octets:

  int rc;          /* Return code */
  mu_stream_t flt; /* Filter stream */

  rc = mu_filter_create (&flt, input, "base64", MU_FILTER_ENCODE, MU_STREAM_READ);

It is supposed that input is an object of type mu_stream_t, initialized previously.

For the sake of completeness, the same effect can be achieved (with a slight loss in performance), by creating the following filter chain: "B + linelen 76". This approach is illustrated in the example below:

  int rc;          /* Return code */
  mu_stream_t flt; /* Filter stream */
  char *argv[] = { "B", "+", "linelen", "76", NULL };

  rc = mu_filter_chain_create (&flt, input, MU_FILTER_ENCODE, MU_STREAM_READ, 4, argv);

See also