text
stringlengths
0
357
do_quote_char = 1;
}
break;
}
if (do_quote_char)
{
snprintf(hex, 4, "=%2.2X", (unsigned char) * cur);
if (mmap_string_append(mmapstr, hex)==NULL) {
return 0;
}
col += 3;
}
else
{
if (* cur==' ') {
if (mmap_string_append_c(mmapstr, '_')==NULL) {
return 0;
}
}
else {
if (mmap_string_append_c(mmapstr, * cur)==NULL) {
return 0;
}
}
col += 3;
}
cur++;
}
if (mmap_string_append(mmapstr, "?=")==NULL) {
return 0;
}
return 1;
}
static void get_word(const char* begin, const char** pend, int* pto_be_quoted)
{
const char* cur = begin;
while ((* cur != ' ') && (* cur != '\t') && (* cur != '\0')) {
cur ++;
}
#if MAX_IMF_LINE != 666
if (cur - begin +
1 /* minimum column of string in a
folded header */ > MAX_IMF_LINE)
*pto_be_quoted = 1;
else
#endif
*pto_be_quoted = to_be_quoted(begin, cur - begin);
*pend = cur;
}
/**
* Encode non-ascii-strings as `=?UTF-8?Q?Bj=c3=b6rn_Petersen?=`.
* Belongs to RFC 2047: https://tools.ietf.org/html/rfc2047
*
* We do not fold at position 72; this would result in empty words as `=?utf-8?Q??=` which are correct,
* but cannot be displayed by some mail programs (eg. Android Stock Mail).
* however, this is not needed, as long as _one_ word is not longer than 72 characters.
* _if_ it is, the display may get weird. This affects the subject only.
* the best solution wor all this would be if libetpan encodes the line as only libetpan knowns when a header line is full.
*
* @param to_encode Null-terminated UTF-8-string to encode.
* @return Returns the encoded string which must be free()'d when no longed needed.
* On errors, NULL is returned.
*/
char* dc_encode_header_words(const char* to_encode)
{
char* ret_str = NULL;
const char* cur = to_encode;
MMAPString* mmapstr = mmap_string_new("");
if (to_encode==NULL || mmapstr==NULL) {
goto cleanup;
}
while (* cur != '\0')
{
const char * begin;
const char * end;
int do_quote;
int quote_words;
begin = cur;
end = begin;
quote_words = 0;
do_quote = 1;
while (* cur != '\0')
{
get_word(cur, &cur, &do_quote);
if (do_quote) {