]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: Removed existing envelope parsing function.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 23 Oct 2016 10:10:44 +0000 (12:10 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 20 Feb 2017 09:25:54 +0000 (11:25 +0200)
This is currently only used by imaptest. Alternative API is provided in later commit.

src/lib-imap/imap-envelope.c
src/lib-imap/imap-envelope.h

index 42e46b8c00f9689913331e58a9150f25ede52cd7..f377ddbf94fbc1fddb8513c7df0a3b6b586af6d8 100644 (file)
@@ -224,191 +224,3 @@ void imap_envelope_write_part_data(struct message_part_envelope_data *data,
        str_append_c(str, ' ');
        str_append(str, NVL(data->message_id, "NIL"));
 }
-
-static bool imap_address_arg_append(const struct imap_arg *arg, string_t *str,
-                                   bool *in_group, bool *begin_group)
-{
-       const struct imap_arg *list_args;
-       unsigned int list_count;
-       const char *args[4];
-       int i;
-
-       if (!imap_arg_get_list_full(arg, &list_args, &list_count))
-               return FALSE;
-
-       /* we require 4 arguments, strings or NILs */
-       if (list_count < 4)
-               return FALSE;
-
-       for (i = 0; i < 4; i++) {
-               if (!imap_arg_get_nstring(&list_args[i], &args[i]))
-                       return FALSE;
-       }
-
-       if (*in_group && args[0] == NULL && args[1] == NULL &&
-           args[2] == NULL && args[3] == NULL) {
-               /* end of group */
-               str_append_c(str, ';');
-               *in_group = FALSE;
-               *begin_group = FALSE;
-               return TRUE;
-       }
-
-       if (str_len(str) > 0 && !*begin_group)
-               str_append(str, ", ");
-
-       if (!*in_group && args[0] == NULL && args[1] == NULL &&
-           args[2] != NULL && args[3] == NULL) {
-               /* beginning of group */
-               str_append(str, args[2]);
-               str_append(str, ": ");
-               *in_group = TRUE;
-               *begin_group = TRUE;
-               return TRUE;
-       }
-       *begin_group = FALSE;
-
-       /* a) mailbox@domain
-          b) name <@route:mailbox@domain> */
-       if (args[0] == NULL && args[1] == NULL) {
-               if (args[2] != NULL)
-                       str_append(str, args[2]);
-               if (args[3] != NULL) {
-                       str_append_c(str, '@');
-                       str_append(str, args[3]);
-               }
-       } else {
-               if (args[0] != NULL) {
-                       str_append(str, args[0]);
-                       str_append_c(str, ' ');
-               }
-
-               str_append_c(str, '<');
-               if (args[1] != NULL) {
-                       str_append_c(str, '@');
-                       str_append(str, args[1]);
-                       str_append_c(str, ':');
-               }
-               if (args[2] != NULL)
-                       str_append(str, args[2]);
-               if (args[3] != NULL) {
-                       str_append_c(str, '@');
-                       str_append(str, args[3]);
-               }
-               str_append_c(str, '>');
-       }
-       return TRUE;
-}
-
-static const char *imap_envelope_parse_address(const struct imap_arg *arg)
-{
-       const struct imap_arg *list_args;
-       string_t *str;
-       bool in_group;
-       bool begin_group;
-
-       if (!imap_arg_get_list(arg, &list_args))
-               return NULL;
-
-       in_group = FALSE;
-       begin_group = FALSE;
-       str = t_str_new(128);
-
-       for (; !IMAP_ARG_IS_EOL(list_args); list_args++) {
-               if (!imap_address_arg_append(list_args, str, &in_group, &begin_group))
-                       return NULL;
-       }
-
-       return str_c(str);
-}
-
-static const char *imap_envelope_parse_first_mailbox(const struct imap_arg *arg)
-{
-       const struct imap_arg *list_args;
-       const char *str;
-       unsigned int list_count;
-
-       /* ((...)(...) ...) */
-       if (!imap_arg_get_list(arg, &list_args))
-               return NULL;
-       if (IMAP_ARG_IS_EOL(list_args))
-               return "";
-
-       /* (name route mailbox domain) */
-       if (!imap_arg_get_list_full(arg, &list_args, &list_count) ||
-           list_count != 4)
-               return NULL;
-       if (!imap_arg_get_nstring(&list_args[2], &str))
-               return NULL;
-       return t_strdup(str);
-}
-
-static bool
-imap_envelope_parse_arg(const struct imap_arg *arg,
-                       enum imap_envelope_field field,
-                       const char *envelope,
-                       enum imap_envelope_result_type result_type,
-                       const char **result)
-{
-       const char *value = NULL;
-
-       if (arg->type == IMAP_ARG_NIL) {
-               *result = NULL;
-               return TRUE;
-       }
-
-       switch (result_type) {
-       case IMAP_ENVELOPE_RESULT_TYPE_STRING:
-               if (field >= IMAP_ENVELOPE_FROM && field <= IMAP_ENVELOPE_BCC)
-                       value = imap_envelope_parse_address(arg);
-               else {
-                       if (imap_arg_get_nstring(arg, &value))
-                               value = t_strdup(value);
-               }
-               break;
-       case IMAP_ENVELOPE_RESULT_TYPE_FIRST_MAILBOX:
-               i_assert(field >= IMAP_ENVELOPE_FROM &&
-                        field <= IMAP_ENVELOPE_BCC);
-               value = imap_envelope_parse_first_mailbox(arg);
-               break;
-       }
-
-       *result = value;
-       if (value != NULL)
-               return TRUE;
-       else {
-               i_error("Invalid field %u in IMAP envelope: %s",
-                       field, envelope);
-               return FALSE;
-       }
-}
-
-bool imap_envelope_parse(const char *envelope, enum imap_envelope_field field,
-                        enum imap_envelope_result_type result_type,
-                        const char **result)
-{
-       struct istream *input;
-       struct imap_parser *parser;
-       const struct imap_arg *args;
-       int ret;
-
-       i_assert(field < IMAP_ENVELOPE_FIELDS);
-
-       input = i_stream_create_from_data(envelope, strlen(envelope));
-       parser = imap_parser_create(input, NULL, (size_t)-1);
-
-       (void)i_stream_read(input);
-       ret = imap_parser_read_args(parser, field+1, 0, &args);
-       if (ret > (int)field) {
-               ret = imap_envelope_parse_arg(&args[field], field,
-                                             envelope, result_type, result);
-       } else {
-               i_error("Error parsing IMAP envelope: %s", envelope);
-               *result = NULL;
-               ret = FALSE;
-       }
-
-       imap_parser_unref(&parser);
-       i_stream_destroy(&input);
-       return ret;
-}
index 14c81c62a985293977e251d3701c8e5e331cfa4c..c3a7121f4118bd696a7d193042068aee56769a7a 100644 (file)
@@ -19,11 +19,6 @@ enum imap_envelope_field {
        IMAP_ENVELOPE_FIELDS
 };
 
-enum imap_envelope_result_type {
-       IMAP_ENVELOPE_RESULT_TYPE_STRING,
-       IMAP_ENVELOPE_RESULT_TYPE_FIRST_MAILBOX
-};
-
 struct message_part_envelope_data;
 
 extern const char *imap_envelope_headers[];
@@ -39,10 +34,4 @@ void imap_envelope_parse_header(pool_t pool,
 void imap_envelope_write_part_data(struct message_part_envelope_data *data,
                                   string_t *str);
 
-/* Parse envelope and store specified field to result. NIL is stored as NULL.
-   Returns TRUE if successful. */
-bool imap_envelope_parse(const char *envelope, enum imap_envelope_field field,
-                        enum imap_envelope_result_type result_type,
-                        const char **result);
-
 #endif