Back to index

courier  0.68.2
Functions
filter.c File Reference
#include "config.h"
#include "filter.h"
#include "buf.h"
#include "sqwebmail.h"
#include <string.h>

Go to the source code of this file.

Functions

static int converted_text (const char *buf, size_t size, void *arg)
void filter_start (struct filter_info *info, const char *charset, void(*handler)(const char *, size_t, void *), void *arg)
void filter (struct filter_info *info, const unicode_char *ptr, size_t cnt)
void filter_passthru (struct filter_info *info, const unicode_char *ptr, size_t cnt)
void filter_end (struct filter_info *info)

Function Documentation

static int converted_text ( const char *  buf,
size_t  size,
void *  arg 
) [static]

Definition at line 16 of file filter.c.

{
       struct filter_info *info=(struct filter_info *)arg;

       (*info->handler_func)(buf, size, info->func_arg);
       return 0;
}

Here is the caller graph for this function:

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

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 info,
const char *  charset,
void(*)(const char *, size_t, void *)  handler,
void *  arg 
)

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: