/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "base64.h"
#include "message-header-encode.h"
#define IS_LWSP(c) \
((c) == ' ' || (c) == '\t' || (c) == '\n')
unsigned int i, unsigned int len)
{
switch (input[i]) {
case '\r':
return TRUE;
i++;
/* fall through - verify the LF as well */
case '\n':
if (i+1 == len) {
/* trailing LF - we need to drop it */
return TRUE;
}
/* LF not followed by whitespace - we need to
add the whitespace */
return TRUE;
}
break;
case '\t':
/* TAB doesn't need to be encoded */
break;
case '=':
/* <LWSP>=? - we need to check backwards a bit to see if
there is LWSP (note that we don't want to return TRUE for
the LWSP itself yet, so we need to do this backwards
check) */
return TRUE;
break;
default:
/* 8bit chars */
if ((input[i] & 0x80) != 0)
return TRUE;
/* control chars */
if (input[i] < 32)
return TRUE;
break;
}
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 an UTF8 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;
}
}
{
}
{
const unsigned char *next_line_input;
unsigned int next_line_len = 0;
/* find the first word that needs encoding */
for (i = 0; i < len; i++) {
break;
}
if (i == len) {
/* no encoding necessary */
return;
}
/* go back to the beginning of the word so it is fully encoded */
i--;
}
/* write the prefix */
first_line_len = j = i;
if (j != 0)
first_line_len = j;
input += i;
len -= i;
/* we'll encode data only up to the next LF, the rest is handled
recursively. */
if (next_line_input != NULL) {
cur_line_len--;
}
len = cur_line_len;
}
/* find the last word that needs encoding */
for (i = 0; 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 (enc_len == 0)
;
else if (use_q)
else
if (next_line_input != NULL) {
/* we're at [CR]LF */
i = 0;
if (next_line_input[0] == '\r') {
i++;
} else {
}
if (++i == next_line_len)
return; /* drop trailing [CR]LF */
if (cr)
i++;
} else {
/* make it valid folding whitespace by adding a TAB */
}
output);
}
}