Difference between revisions of "Base64 (filter)"

From Mailutils
Jump to navigationJump to search
m
m
Line 18: Line 18:
 
   mu_stream_t flt; /* Filter stream */
 
   mu_stream_t flt; /* Filter stream */
  
   rc = mu_filter_stream_create (&flt, input, "base64", MU_FILTER_ENCODE, MU_STREAM_READ);
+
   rc = mu_filter_create (&flt, input, "base64", MU_FILTER_ENCODE, MU_STREAM_READ);
 
</source>
 
</source>
  

Revision as of 19:07, 5 September 2015

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