]> dgit.raspbian.org Git - dovecot.git/commitdiff
[PATCH 3/4] lib-mail: o_stream_dot_sendv() - Use enumeration to define the items...
authorMarco Bettini <marco.bettini@open-xchange.com>
Fri, 10 Apr 2026 08:49:49 +0000 (08:49 +0000)
committerNoah Meyerhans <noahm@debian.org>
Wed, 16 Sep 2026 19:06:35 +0000 (15:06 -0400)
Gbp-Pq: Name 0003-lib-mail-o_stream_dot_sendv-Use-enumeration-to-defin.patch

src/lib-mail/ostream-dot.c

index 9d5411abb46bba9d92b428875afdef8a7c6a859b..81930a0c57cef2f579b162e8bd42b93c58ef7b01 100644 (file)
@@ -71,6 +71,12 @@ o_stream_dot_close(struct iostream_private *stream, bool close_parent)
                o_stream_close(dstream->ostream.parent);
 }
 
+enum o_stream_dot_sendv_add {
+       ADD_NONE,
+       ADD_CR,
+       ADD_DOT,
+};
+
 static ssize_t
 o_stream_dot_sendv(struct ostream_private *stream,
                    const struct const_iovec *iov, unsigned int iov_count)
@@ -106,7 +112,7 @@ o_stream_dot_sendv(struct ostream_private *stream,
                p = data;
                pend = CONST_PTR_OFFSET(data, size);
                for (; p < pend && ((size_t)(p - data) + 2) <= max_bytes; p++) {
-                       char add = 0;
+                       enum o_stream_dot_sendv_add add = ADD_NONE;
 
                        size = pend - p;
                        switch (dstream->state) {
@@ -122,8 +128,7 @@ o_stream_dot_sendv(struct ostream_private *stream,
                                switch (*p) {
                                case '\n':
                                        dstream->state = STREAM_STATE_CRLF;
-                                       /* add missing CR */
-                                       add = '\r';
+                                       add = ADD_CR;
                                        break;
                                case '\r':
                                        dstream->state = STREAM_STATE_CR;
@@ -155,12 +160,10 @@ o_stream_dot_sendv(struct ostream_private *stream,
                                        break;
                                case '\n':
                                        dstream->state = STREAM_STATE_CRLF;
-                                       /* add missing CR */
-                                       add = '\r';
+                                       add = ADD_CR;
                                        break;
                                case '.':
-                                       /* add dot */
-                                       add = '.';
+                                       add = ADD_DOT;
                                        /* fall through */
                                default:
                                        dstream->state = STREAM_STATE_NONE;
@@ -185,12 +188,24 @@ o_stream_dot_sendv(struct ostream_private *stream,
                                }
                                /* insert byte (substitute one with pair) */
                                data++;
-                               iovn.iov_base = (add == '\r' ? "\r\n" : "..");
-                               iovn.iov_len = 2;
+
+                               switch(add) {
+                               case ADD_DOT:
+                                       iovn.iov_base = "..";
+                                       iovn.iov_len = 2;
+                                       break;
+                               case ADD_CR:
+                                       iovn.iov_base = "\r\n";
+                                       iovn.iov_len = 2;
+                                       break;
+                               default:
+                                       i_unreached();
+                               }
+
                                array_push_back(&iov_arr, &iovn);
-                               i_assert(max_bytes >= 2);
-                               max_bytes -= 2;
-                               added++;
+                               i_assert(max_bytes >= iovn.iov_len);
+                               max_bytes -= iovn.iov_len;
+                               added += iovn.iov_len - 1;
                                sent++;
                        }
                }