message-header-encode.c revision 5b6e0b6569d5e79ddb868525063cfd04009437b4
/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "base64.h"
#include "message-header-encode.h"
#define MIME_MAX_LINE_LEN 76
#define IS_LWSP(c) \
((c) == ' ' || (c) == '\t' || (c) == '\n')
static bool input_idx_need_encoding(const unsigned char *input,
unsigned int i, unsigned int len)
{
/* 8bit chars */
if ((input[i] & 0x80) != 0)
return TRUE;
/* control chars */
if (input[i] < 32)
return TRUE;
/* <LWSP>=? */
return TRUE;
return FALSE;
}
{
unsigned int i, line_len_left;
} else {
}
for (i = 0; i < len; i++) {
if (line_len_left < 3) {
/* if we're not at the beginning of a character,
go backwards until we are */
i--;
}
MIME_WRAPPER_LEN - 1;
}
switch (input[i]) {
case ' ':
break;
case '=':
case '?':
case '_':
line_len_left -= 2;
break;
default:
line_len_left -= 2;
} else {
}
break;
}
}
}
{
line_len = 1;
}
for (;;) {
do {
max--;
else {
/* all of it doesn't fit. find a character where we
can split it from. */
max--;
}
max > 0);
if (max > 0) {
}
if (len == 0)
break;
line_len = 1;
}
}
{
}
{
bool use_q;
/* find the first word that needs encoding */
for (i = 0; i < len; i++) {
break;
}
if (i == len) {
/* no encoding necessary */
return;
}
first_idx = i;
first_idx--;
/* find the last word that needs encoding */
for (; i < len; i++) {
last_idx = i + 1;
enc_chars++;
}
}
last_idx++;
/* figure out if we should use Q or B encoding. Prefer Q if it's not
too much larger. */
/* and do it */
if (use_q) {
} else {
}
}