Back to index

courier  0.68.2
Classes | Functions
filter.h File Reference
#include <stdlib.h>
#include "unicode/unicode.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  filter_info

Functions

void filter_start (struct filter_info *, const char *, void(*)(const char *, size_t, void *), void *)
void filter (struct filter_info *, const unicode_char *, size_t)
void filter_passthru (struct filter_info *info, const unicode_char *ptr, size_t cnt)
void filter_end (struct filter_info *info)

Function Documentation

void filter ( struct filter_info ,
const unicode_char ,
size_t   
)

Definition at line 47 of file filter.c.

{
       size_t i, prev;

       if (!info->handle)
              return;

       i=prev=0;

       while (1)
       {
              const char *p=0;
              unicode_char prevchar=info->prevchar;

              if (i < cnt)
              {
                     info->prevchar=ptr[i];

                     if (ptr[i] == '\n')
                     {
                            info->u_w=0;
                     }
                     else
                     {
                            /* Force-break excessively long lines */

                            size_t uc_w=unicode_wcwidth(ptr[i]);

                            if (uc_w + info->u_w > info->linesize &&
                                unicode_grapheme_break(prevchar, ptr[i]))
                            {
                                   unicode_char nl='\n';

                                   if (prev < i)
                                          libmail_u_convert_uc
                                                 (info->handle,
                                                  ptr+prev, i-prev);
                                   prev=i;

                                   libmail_u_convert_uc(info->handle,
                                                      &nl, 1);
                                   info->u_w=0;
                            }

                            info->u_w += uc_w;
                     }

                     switch (ptr[i]) {
                     case '<':
                            p="&lt;";
                            break;
                     case '>':
                            p="&gt;";
                            break;
                     case '&':
                            p="&amp;";
                            break;
                     case '"':
                            p="&quot;";
                            break;
                     default:
                            ++i;
                            continue;
                     }
              }

              if (prev < i)
                     libmail_u_convert_uc(info->handle, ptr+prev, i-prev);
              prev=++i;

              if (!p)
                     break;

              while (*p)
              {
                     unicode_char uc= *p++;

                     libmail_u_convert_uc(info->handle, &uc, 1);
              }
       }
}

Here is the call graph for this function:

void filter_end ( struct filter_info info)

Definition at line 136 of file filter.c.

{
       if (info->handle)
       {
              libmail_u_convert_deinit(info->handle,
                                    &info->conversion_error);
              info->handle=NULL;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void filter_passthru ( struct filter_info info,
const unicode_char ptr,
size_t  cnt 
)

Definition at line 130 of file filter.c.

{
       libmail_u_convert_uc(info->handle, ptr, cnt);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void filter_start ( struct filter_info ,
const char *  ,
void(*)(const char *, size_t, void *)  ,
void *   
)

Definition at line 26 of file filter.c.

{
       info->conversion_error=0;
       info->handle=libmail_u_convert_init(libmail_u_ucs4_native,
                                       charset,
                                       converted_text, info);

       if (info->handle == NULL)
              info->conversion_error=1;

       info->handler_func=handler;
       info->func_arg=arg;
       info->u_w=0;

       info->linesize=MYLINESIZE + 10;
       info->prevchar='\n';
}

Here is the call graph for this function:

Here is the caller graph for this function: