2 ** Copyright 2003-2011 Double Precision, Inc. See COPYING for
3 ** distribution information.
11 #include "../unicode/unicode.h"
13 static const char *libmail_encode_autodetect(int use7bit
,
14 int (*func
)(void *), void *arg
,
27 while ((c
= (*func
)(arg
)) != EOF
)
29 unsigned char ch
= (unsigned char)c
;
34 if (ch
< 0x20 || ch
>= 0x80)
36 if (ch
!= '\t' && ch
!= '\r' && ch
!= '\n')
59 if (use7bit
|| longline
)
61 if (bit8cnt
> charcnt
/ 10)
64 return "quoted-printable";
67 return bit8cnt
? "8bit":"7bit";
76 static int read_file(void *arg
)
79 struct file_info
*fi
= (struct file_info
*)arg
;
80 if (fi
->end
>= 0 && fi
->pos
> fi
->end
)
87 static int read_string(void * arg
)
90 unsigned char **strp
= (unsigned char **)arg
;
98 const char *libmail_encode_autodetect_fp(FILE *fp
, int use7bit
,
101 return libmail_encode_autodetect_fpoff(fp
, use7bit
, 0, -1,
105 const char *libmail_encode_autodetect_fpoff(FILE *fp
, int use7bit
,
106 off_t start_pos
, off_t end_pos
,
110 off_t orig_pos
= ftell(fp
);
111 off_t pos
= orig_pos
;
116 if (fseek(fp
, start_pos
, SEEK_SET
) == (off_t
)-1)
126 rc
= libmail_encode_autodetect(use7bit
, &read_file
, &fi
,
129 if (fseek(fp
, orig_pos
, SEEK_SET
) == (off_t
)-1)
134 const char *libmail_encode_autodetect_buf(const char *str
, int use7bit
)
136 return libmail_encode_autodetect(use7bit
, &read_string
, &str
,