Back to index

courier  0.68.2
Classes | Functions
encodeautodetect.c File Reference
#include "encode.h"
#include <string.h>
#include <stdlib.h>
#include "../unicode/unicode.h"

Go to the source code of this file.

Classes

struct  file_info

Functions

static const char * libmail_encode_autodetect (int use7bit, int(*func)(void *), void *arg, int *binaryflag)
static int read_file (void *arg)
static int read_string (void *arg)
const char * libmail_encode_autodetect_fp (FILE *fp, int use7bit, int *binaryflag)
const char * libmail_encode_autodetect_fpoff (FILE *fp, int use7bit, off_t start_pos, off_t end_pos, int *binaryflag)
const char * libmail_encode_autodetect_buf (const char *str, int use7bit)

Class Documentation

struct file_info

Definition at line 70 of file encodeautodetect.c.

Class Members
off_t end
FILE * fp
off_t pos

Function Documentation

static const char* libmail_encode_autodetect ( int  use7bit,
int(*)(void *)  func,
void *  arg,
int *  binaryflag 
) [static]

Definition at line 13 of file encodeautodetect.c.

{
       int    l=0;
       int    longline=0;
       int c;

       size_t charcnt=0;
       size_t bit8cnt=0;

       if (binaryflag)
              *binaryflag=0;

       while ((c = (*func)(arg)) != EOF)
       {
              unsigned char ch= (unsigned char)c;

              ++charcnt;

              ++l;
              if (ch < 0x20 || ch >= 0x80)
              {
                     if (ch != '\t' && ch != '\r' && ch != '\n')
                     {
                            ++bit8cnt;
                            l += 2;
                     }
              }

              if (ch == 0)
              {
                     if (binaryflag)
                            *binaryflag=1;

                     return "base64";
              }

              if (ch == '\n')      l=0;
              else if (l > 990)
              {
                     longline=1;
              }

       }

       if (use7bit || longline)
       {
              if (bit8cnt > charcnt / 10)
                     return "base64";

              return "quoted-printable";
       }

       return bit8cnt ? "8bit":"7bit";
}

Here is the caller graph for this function:

const char* libmail_encode_autodetect_buf ( const char *  str,
int  use7bit 
)

Definition at line 134 of file encodeautodetect.c.

{
       return libmail_encode_autodetect(use7bit, &read_string, &str,
                                    NULL);
}

Here is the call graph for this function:

const char* libmail_encode_autodetect_fp ( FILE *  fp,
int  use7bit,
int *  binaryflag 
)

Definition at line 98 of file encodeautodetect.c.

{
       return libmail_encode_autodetect_fpoff(fp, use7bit, 0, -1,
                                          binaryflag);
}

Here is the call graph for this function:

const char* libmail_encode_autodetect_fpoff ( FILE *  fp,
int  use7bit,
off_t  start_pos,
off_t  end_pos,
int *  binaryflag 
)

Definition at line 105 of file encodeautodetect.c.

{
struct file_info fi;
off_t orig_pos = ftell(fp);
off_t pos = orig_pos;
const char *rc;

       if (start_pos >= 0)
       {
              if (fseek(fp, start_pos, SEEK_SET) == (off_t)-1)
                     return NULL;
              else
                     pos = start_pos;
       }

       fi.fp = fp;
       fi.pos = pos;
       fi.end = end_pos;

       rc = libmail_encode_autodetect(use7bit, &read_file, &fi,
                                   binaryflag);
  
       if (fseek(fp, orig_pos, SEEK_SET) == (off_t)-1)
              return NULL;
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int read_file ( void *  arg) [static]

Definition at line 76 of file encodeautodetect.c.

{
int c;
struct file_info *fi = (struct file_info *)arg;
       if (fi->end >= 0 && fi->pos > fi->end)
              return EOF;
       c = getc(fi->fp);
       fi->pos++;
       return c;
}

Here is the caller graph for this function:

static int read_string ( void *  arg) [static]

Definition at line 87 of file encodeautodetect.c.

{
int c;
unsigned char **strp = (unsigned char **)arg;
       if (**strp == 0)
              return EOF;
       c = (int)**strp;
       (*strp)++;
       return c;
}