]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-address - Add raw field to struct smtp_address.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Thu, 12 Sep 2019 23:57:18 +0000 (01:57 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 4 Oct 2019 11:59:35 +0000 (13:59 +0200)
src/lda/main.c
src/lib-smtp/smtp-address.h
src/lib-smtp/test-smtp-client-errors.c
src/lib-smtp/test-smtp-payload.c
src/lib-smtp/test-smtp-submit.c

index 63392443c04320b48fb0f8c2124290061e3029d7..7076460db49b0f67de63bae0e333b35e5ed1c399 100644 (file)
@@ -33,7 +33,7 @@
 #include <sysexits.h>
 
 const struct smtp_address default_envelope_sender = {
-       "MAILER-DAEMON", NULL
+       .localpart = "MAILER-DAEMON",
 };
 
 /* After buffer grows larger than this, create a temporary file to /tmp
index d3cb224933ddc5a5daa4fe1ec9ca6a9e904fa8fa..03c914f0fa66a41bb4c688f0cccdd56db245d2b1 100644 (file)
@@ -24,8 +24,17 @@ enum smtp_address_parse_flags {
 };
 
 struct smtp_address {
+       /* Localpart */
        const char *localpart;
+       /* Domain */
        const char *domain;
+       /* Raw, unparsed address. If localpart == NULL, the value of this field
+          is syntactically invalid and MUST NOT be used for any purposes that
+          may be visible to external systems. It can be e.g. used for logging.
+          This is always in mailbox format, meaning that there are no
+          surrounding '<' and '>'.
+        */
+       const char *raw;
 };
 
 ARRAY_DEFINE_TYPE(smtp_address, struct smtp_address *);
index f3c28d2279a86b0c3ae4a4529942807028cddac1..db0a43987ef380ab8543e08255f4c9519af96588 100644 (file)
@@ -743,12 +743,14 @@ test_client_broken_payload(
                SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
                SMTP_CLIENT_SSL_MODE_NONE, NULL);
        strans = smtp_client_transaction_create(sconn,
-               &((struct smtp_address){"sender", "example.com"}), NULL, 0,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}), NULL, 0,
                test_client_broken_payload_finished, NULL);
        smtp_client_connection_unref(&sconn);
 
        smtp_client_transaction_add_rcpt(strans,
-               &((struct smtp_address){"rcpt", "example.com"}), NULL,
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}), NULL,
                test_client_broken_payload_rcpt_to_cb,
                test_client_broken_payload_rcpt_data_cb, NULL);
        smtp_client_transaction_send(strans, input,
@@ -802,12 +804,14 @@ test_client_broken_payload_later(
                SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
                SMTP_CLIENT_SSL_MODE_NONE, NULL);
        strans = smtp_client_transaction_create(sconn,
-               &((struct smtp_address){"sender", "example.com"}), NULL, 0,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}), NULL, 0,
                test_client_broken_payload_finished, NULL);
        smtp_client_connection_unref(&sconn);
 
        smtp_client_transaction_add_rcpt(strans,
-               &((struct smtp_address){"rcpt", "example.com"}), NULL,
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}), NULL,
                test_client_broken_payload_rcpt_to_cb,
                test_client_broken_payload_rcpt_data_cb, NULL);
        smtp_client_transaction_send
@@ -1026,12 +1030,14 @@ test_client_connection_lost_submit(struct _connection_lost *ctx,
                SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
                SMTP_CLIENT_SSL_MODE_NONE, NULL);
        strans = smtp_client_transaction_create(sconn,
-               &((struct smtp_address){"sender", "example.com"}), NULL, 0,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}), NULL, 0,
                test_client_connection_lost_finished, pctx);
        smtp_client_connection_unref(&sconn);
 
        smtp_client_transaction_add_rcpt(strans,
-               &((struct smtp_address){"rcpt", "example.com"}), NULL,
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}), NULL,
                test_client_connection_lost_rcpt_to_cb,
                test_client_connection_lost_rcpt_data_cb, pctx);
        smtp_client_transaction_send
@@ -1339,7 +1345,8 @@ test_client_unexpected_reply_submit1(struct _unexpected_reply_peer *pctx)
        timeout_remove(&pctx->to);
 
        smtp_client_transaction_add_rcpt(pctx->trans,
-               &((struct smtp_address){"rcpt", "example.com"}), NULL,
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}), NULL,
                test_client_unexpected_reply_rcpt_to_cb,
                test_client_unexpected_reply_rcpt_data_cb, pctx);
 
@@ -1361,7 +1368,8 @@ test_client_unexpected_reply_submit(struct _unexpected_reply *ctx,
                SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
                SMTP_CLIENT_SSL_MODE_NONE, NULL);
        pctx->trans = smtp_client_transaction_create(pctx->conn,
-               &((struct smtp_address){"sender", "example.com"}), NULL, 0,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}), NULL, 0,
                test_client_unexpected_reply_finished, pctx);
        smtp_client_connection_connect(pctx->conn,
                test_client_unexpected_reply_login_cb, (void *)pctx);
@@ -1800,7 +1808,8 @@ test_client_premature_reply_submit2(struct _premature_reply_peer *pctx)
                i_debug("SUBMIT2[%u]", pctx->index);
 
        smtp_client_transaction_add_rcpt(pctx->trans,
-               &((struct smtp_address){"rcpt", "example.com"}), NULL,
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}), NULL,
                test_client_premature_reply_rcpt_to_cb,
                test_client_premature_reply_rcpt_data_cb, pctx);
 
@@ -1839,7 +1848,8 @@ test_client_premature_reply_submit(struct _premature_reply *ctx,
                SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
                SMTP_CLIENT_SSL_MODE_NONE, NULL);
        pctx->trans = smtp_client_transaction_create(conn,
-               &((struct smtp_address){"sender", "example.com"}), NULL, 0,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}), NULL, 0,
                test_client_premature_reply_finished, pctx);
        smtp_client_connection_connect(conn,
                test_client_premature_reply_login_cb, (void *)pctx);
@@ -2124,10 +2134,12 @@ test_client_early_data_reply_submit(struct _early_data_reply *ctx,
                test_client_early_data_reply_login_cb, (void *)pctx);
 
        pctx->trans = smtp_client_transaction_create(conn,
-               &((struct smtp_address){"sender", "example.com"}), NULL, 0,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}), NULL, 0,
                test_client_early_data_reply_finished, pctx);
        smtp_client_transaction_add_rcpt(pctx->trans,
-               &((struct smtp_address){"rcpt", "example.com"}), NULL,
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}), NULL,
                test_client_early_data_reply_rcpt_to_cb,
                test_client_early_data_reply_rcpt_data_cb, pctx);
        smtp_client_transaction_start(pctx->trans,
@@ -3152,7 +3164,8 @@ test_client_authentication_failed_submit(struct _authentication_failed *ctx,
                SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
                SMTP_CLIENT_SSL_MODE_NONE, &smtp_set);
        pctx->trans = smtp_client_transaction_create(pctx->conn,
-               &((struct smtp_address){"sender", "example.com"}), NULL, 0,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}), NULL, 0,
                test_client_authentication_failed_finished, pctx);
        smtp_client_connection_connect(pctx->conn,
                test_client_authentication_failed_login_cb, (void *)pctx);
@@ -3161,7 +3174,8 @@ test_client_authentication_failed_submit(struct _authentication_failed *ctx,
        smtp_client_connection_unref(&pctx->conn);
 
        smtp_client_transaction_add_rcpt(pctx->trans,
-               &((struct smtp_address){"rcpt", "example.com"}), NULL,
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}), NULL,
                test_client_authentication_failed_rcpt_to_cb,
                test_client_authentication_failed_rcpt_data_cb, pctx);
 
@@ -3403,7 +3417,8 @@ test_client_transaction_timeout_submit1(struct _transaction_timeout_peer *pctx)
        timeout_remove(&pctx->to);
 
        smtp_client_transaction_add_rcpt(pctx->trans,
-               &((struct smtp_address){"rcpt", "example.com"}), NULL,
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}), NULL,
                test_client_transaction_timeout_rcpt_to_cb,
                test_client_transaction_timeout_rcpt_data_cb, pctx);
 
@@ -3425,7 +3440,8 @@ test_client_transaction_timeout_submit(struct _transaction_timeout *ctx,
                SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
                SMTP_CLIENT_SSL_MODE_NONE, NULL);
        pctx->trans = smtp_client_transaction_create(pctx->conn,
-               &((struct smtp_address){"sender", "example.com"}), NULL, 0,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}), NULL, 0,
                test_client_transaction_timeout_finished, pctx);
        smtp_client_transaction_set_timeout(pctx->trans, 1000);
        smtp_client_transaction_start(pctx->trans,
index d9e773397865900e15bda8d90845914823ff8a19..72a8464a61af0134e400fe06c9e2efe50aa23061 100644 (file)
@@ -754,7 +754,8 @@ static void test_client_continue(void *dummy ATTR_UNUSED)
 
                tctrans->conn->trans = smtp_client_transaction_create(
                        tctrans->conn->conn,
-                       &((struct smtp_address){"user", "example.com"}),
+                       &((struct smtp_address){.localpart = "user",
+                                               .domain = "example.com"}),
                        &mail_params, 0,
                        test_client_transaction_finish, tctrans);
 
index 6165be5eab75fce22b732a39c8efb2917d9aef25..5ddf97194dd8cdffa8c43306623d9e774c198a4b 100644 (file)
@@ -760,13 +760,17 @@ test_client_denied_second_rcpt(const struct smtp_submit_settings *submit_set)
        smtp_submit_set.submission_timeout = 1000;
 
        i_zero(&smtp_input);
-       smtp_submit = smtp_submit_init_simple(&smtp_input, &smtp_submit_set,
-               &((struct smtp_address){"sender", "example.com"}));
+       smtp_submit = smtp_submit_init_simple(
+               &smtp_input, &smtp_submit_set,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}));
 
        smtp_submit_add_rcpt(smtp_submit,
-               &((struct smtp_address){"rcpt", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}));
        smtp_submit_add_rcpt(smtp_submit,
-               &((struct smtp_address){"rcpt2", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt2",
+                                       .domain = "example.com"}));
        output = smtp_submit_send(smtp_submit);
        o_stream_nsend_str(output, test_message1);
 
@@ -1475,11 +1479,14 @@ test_client_parallel_delivery(const struct smtp_submit_settings *submit_set)
        i_zero(&smtp_input);
        smtp_submit_set.submission_host =
                t_strdup_printf("127.0.0.1:%u",  bind_ports[0]);
-       smtp_submit1 = smtp_submit_init_simple(&smtp_input, &smtp_submit_set,
-               &((struct smtp_address){"sender", "example.com"}));
+       smtp_submit1 = smtp_submit_init_simple(
+               &smtp_input, &smtp_submit_set,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}));
 
        smtp_submit_add_rcpt(smtp_submit1,
-               &((struct smtp_address){"rcpt", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}));
        output = smtp_submit_send(smtp_submit1);
        o_stream_nsend_str(output, test_message1);
 
@@ -1491,10 +1498,12 @@ test_client_parallel_delivery(const struct smtp_submit_settings *submit_set)
        smtp_submit_set.submission_host =
                t_strdup_printf("127.0.0.1:%u",  bind_ports[1]);
        smtp_submit2 = smtp_submit_init_simple(&smtp_input, &smtp_submit_set,
-               &((struct smtp_address){"sender", "example.com"}));
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}));
 
        smtp_submit_add_rcpt(smtp_submit2,
-               &((struct smtp_address){"rcpt", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}));
        output = smtp_submit_send(smtp_submit2);
        o_stream_nsend_str(output, test_message2);
 
@@ -1567,10 +1576,12 @@ test_client_failed_sendmail(const struct smtp_submit_settings *submit_set)
 
        i_zero(&smtp_input);
        smtp_submit = smtp_submit_init_simple(&smtp_input, &smtp_submit_set,
-               &((struct smtp_address){"sender", "example.com"}));
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}));
 
        smtp_submit_add_rcpt(smtp_submit,
-               &((struct smtp_address){"rcpt", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}));
        output = smtp_submit_send(smtp_submit);
        o_stream_nsend_str(output, test_message1);
 
@@ -1624,10 +1635,12 @@ test_client_successful_sendmail(const struct smtp_submit_settings *submit_set)
 
        i_zero(&smtp_input);
        smtp_submit = smtp_submit_init_simple(&smtp_input, &smtp_submit_set,
-               &((struct smtp_address){"sender", "example.com"}));
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}));
 
        smtp_submit_add_rcpt(smtp_submit,
-               &((struct smtp_address){"rcpt", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}));
        output = smtp_submit_send(smtp_submit);
        o_stream_nsend_str(output, test_message1);
 
@@ -1709,11 +1722,14 @@ test_client_parallel_sendmail(const struct smtp_submit_settings *submit_set)
        /* submit 1 */
        i_zero(&smtp_input);
        smtp_submit_set.sendmail_path = sendmail_path1;
-       smtp_submit1 = smtp_submit_init_simple(&smtp_input, &smtp_submit_set,
-               &((struct smtp_address){"sender", "example.com"}));
+       smtp_submit1 = smtp_submit_init_simple(
+               &smtp_input, &smtp_submit_set,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}));
 
        smtp_submit_add_rcpt(smtp_submit1,
-               &((struct smtp_address){"rcpt", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}));
        output = smtp_submit_send(smtp_submit1);
        o_stream_nsend_str(output, test_message1);
 
@@ -1723,11 +1739,14 @@ test_client_parallel_sendmail(const struct smtp_submit_settings *submit_set)
        /* submit 2 */
        i_zero(&smtp_input);
        smtp_submit_set.sendmail_path = sendmail_path2;
-       smtp_submit2 = smtp_submit_init_simple(&smtp_input, &smtp_submit_set,
-               &((struct smtp_address){"sender", "example.com"}));
+       smtp_submit2 = smtp_submit_init_simple(
+               &smtp_input, &smtp_submit_set,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}));
 
        smtp_submit_add_rcpt(smtp_submit2,
-               &((struct smtp_address){"rcpt", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}));
        output = smtp_submit_send(smtp_submit2);
        o_stream_nsend_str(output, test_message2);
 
@@ -1823,11 +1842,14 @@ test_client_smtp_send_simple(const struct smtp_submit_settings *smtp_set,
        smtp_submit_set.submission_host = host,
 
        i_zero(&smtp_input);
-       smtp_submit = smtp_submit_init_simple(&smtp_input, &smtp_submit_set,
-               &((struct smtp_address){"sender", "example.com"}));
+       smtp_submit = smtp_submit_init_simple(
+               &smtp_input, &smtp_submit_set,
+               &((struct smtp_address){.localpart = "sender",
+                                       .domain = "example.com"}));
 
        smtp_submit_add_rcpt(smtp_submit,
-               &((struct smtp_address){"rcpt", "example.com"}));
+               &((struct smtp_address){.localpart = "rcpt",
+                                       .domain = "example.com"}));
        output = smtp_submit_send(smtp_submit);
        o_stream_nsend_str(output, message);