/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "strescape.h"
#include "smtp-address.h"
#include "message-parser.h"
#include "message-address.h"
#include "rfc822-parser.h"
struct message_address_parser_context {
bool fill_missing;
};
{
else
}
/* quote with "" and escape all '\', '"' and "'" characters if need */
{
const char *p;
/* see if we need to quote it */
for (p = cstr; *p != '\0'; p++) {
break;
}
if (*p == '\0') {
return;
}
/* see if we need to escape it */
for (p = cstr; *p != '\0'; p++) {
if (IS_ESCAPED_CHAR(*p))
break;
}
if (*p == '\0') {
/* only quote */
return;
}
/* quote and escape */
for (; *p != '\0'; p++) {
if (IS_ESCAPED_CHAR(*p))
str_append_c(dest, *p);
}
}
{
int ret;
/*
local-part = dot-atom / quoted-string / obs-local-part
obs-local-part = word *("." word)
*/
else
if (ret < 0)
return -1;
return ret;
}
{
int ret;
return -1;
return ret;
}
{
int ret;
/* obs-domain-list = "@" domain *(*(CFWS / "," ) [CFWS] "@" domain) */
for (;;) {
return 0;
break;
return ret;
}
return 1;
}
{
int ret;
/* "<" [ "@" route ":" ] local-part "@" domain ">" */
return ret;
if (ctx->fill_missing)
return -1;
/* try to continue anyway */
} else {
}
return ret;
}
/* <> address isn't valid */
} else {
return ret;
return ret;
}
}
return -1;
}
{
/*
name-addr = [display-name] angle-addr
display-name = phrase
*/
return -1;
/* Cope with "<address>" without display name */
}
if (parse_angle_addr(ctx) < 0) {
/* broken */
if (ctx->fill_missing)
}
}
{
/* addr-spec = local-part "@" domain */
if (ret <= 0) {
/* end of input or parsing local-part failed */
}
if (ret2 <= 0)
}
else if (ret2 == -2) {
/* So far we've read user without @domain and without
(Display Name). We'll assume that a single "user" (already
read into addr.mailbox) is a mailbox, but if it's followed
by anything else it's a display-name. */
} else {
if (!quoted_string)
}
ret = -1;
}
return ret;
}
{
}
}
}
{
const unsigned char *start;
int ret;
/* mailbox = name-addr / addr-spec */
/* nope, should be addr-spec */
}
}
if (ret < 0)
return ret;
}
{
int ret;
/*
group = display-name ":" [mailbox-list / CFWS] ";" [CFWS]
display-name = phrase
*/
return -1;
/* from now on don't return -1 even if there are problems, so that
the caller knows this is a group */
for (;;) {
/* mailbox-list =
(mailbox *("," mailbox)) / obs-mbox-list */
if (parse_mailbox(ctx) <= 0) {
/* broken mailbox - try to continue anyway. */
}
break;
ret = -1;
break;
}
}
}
if (ret >= 0) {
ret = -1;
else {
}
}
if (ret < 0)
return ret == 0 ? 0 : 1;
}
{
const unsigned char *start;
int ret;
/* address = mailbox / group */
/* not a group, try mailbox */
}
return ret;
}
unsigned int max_addresses)
{
int ret = 0;
/* address-list = (address *("," address)) / obs-addr-list */
while (max_addresses > 0) {
break;
ret = -1;
break;
}
if (ret < 0) {
/* ends with some garbage */
}
break;
}
}
return ret;
}
static struct message_address *
unsigned int max_addresses, bool fill_missing)
{
/* no addresses */
return NULL;
}
return ctx.first_addr;
}
static int
{
int ret;
return -1;
ret = -1;
}
add_address(&ctx);
return (ret < 0 ? -1 : 0);
}
struct message_address *
unsigned int max_addresses, bool fill_missing)
{
if (pool->datastack_pool) {
}
T_BEGIN {
} T_END;
return addr;
}
{
int ret;
if (pool->datastack_pool) {
}
T_BEGIN {
} T_END;
return ret;
}
{
const char *tmp;
/* <> path */
return;
}
/* a) mailbox@domain
b) name <@route:mailbox@domain>
c) group: .. ; */
if (first)
else
if (!in_group) {
/* beginning of group. mailbox is the group
name, others are NULL. */
/* check for MIME encoded-word */
/* MIME encoded-word MUST NOT appear within a 'quoted-string'
so escaping and quoting of phrase is not possible, instead
use obsolete RFC822 phrase syntax which allow spaces */
else
} else {
/* empty group name needs to be quoted */
}
} else {
/* end of group. all fields should be NULL. */
/* cut out the ", " */
}
} else {
/* "Display Name" <mailbox@domain> */
/* check for MIME encoded-word */
/* MIME encoded-word MUST NOT appear within a 'quoted-string'
so escaping and quoting of phrase is not possible, instead
use obsolete RFC822 phrase syntax which allow spaces */
else
}
}
else
}
}
}
}
}
{
}
{
first_addr = *addr;
return message_address_to_string(&first_addr);
}
{
}
{
}
static const char *address_headers[] = {
"From", "Sender", "Reply-To",
"To", "Cc", "Bcc",
"Resent-From", "Resent-Sender", "Resent-To", "Resent-Cc", "Resent-Bcc"
};
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(address_headers); i++) {
return TRUE;
}
return FALSE;
}