[PATCH 5 of 7] Mail: add support for dynamic ID field value : $version, $remote-host

Filipe da Silva fdasilvayy at gmail.com
Tue Jan 14 11:54:22 UTC 2014


# HG changeset patch
# User Filipe da Silva <fdasilvayy at gmail.com>
# Date 1389700272 -3600
#      Tue Jan 14 12:51:12 2014 +0100
# Node ID 147c57844b913f2b1a4dafb44d58e1128039ea03
# Parent  2d3ff21b5373a83dec32759062c4e04a14567c6e
Mail: add support for dynamic ID field value : $version, $remote-host.
This two keyword are replaced at glance.

diff -r 2d3ff21b5373 -r 147c57844b91 src/mail/ngx_mail_imap_handler.c
--- a/src/mail/ngx_mail_imap_handler.c	Tue Jan 14 12:50:51 2014 +0100
+++ b/src/mail/ngx_mail_imap_handler.c	Tue Jan 14 12:51:12 2014 +0100
@@ -305,7 +305,7 @@
 ngx_mail_imap_id(ngx_mail_session_t *s, ngx_connection_t *c)
 {
     ngx_str_t   *arg, server_id;
-    size_t       size, i;
+    size_t       size, i, len;
     u_char      *p, *data;
     ngx_mail_imap_srv_conf_t  *iscf;
 
@@ -351,7 +351,30 @@
 
     // Prepare server response to ID command
     iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module);
-    if (iscf->server_id.len > 0) {
+    if (iscf->server_id.len > 0 && iscf->server_id_fields) {
+        if (iscf->server_id_fields & NGX_IMAP_ID_REMOTE_HOST) {
+            //replace $remote-host by his value
+            len = iscf->server_id.len;
+            server_id.len = len
+                + c->addr_text.len - (sizeof("$remote-host") - 1);
+            server_id.data = ngx_pnalloc(c->pool, server_id.len);
+            if (server_id.data == NULL) {
+                return NGX_ERROR;
+            }
+            data = iscf->server_id.data;
+            data = ngx_strlcasestrn( data, data + len,
+                                    (u_char*) "$remote-host", 12 - 1);
+            size = data - iscf->server_id.data;
+            p = ngx_copy(server_id.data, iscf->server_id.data, size);
+            // push addr_text value
+            p = ngx_copy(p, c->addr_text.data, c->addr_text.len);
+            data += sizeof("$remote-host") - 1;
+            size = len - size - (sizeof("$remote-host") - 1);
+            p = ngx_copy(p, data, size);
+
+        }
+    }
+    else if (iscf->server_id.len > 0) {
         server_id = iscf->server_id;
 
     } else {
diff -r 2d3ff21b5373 -r 147c57844b91 src/mail/ngx_mail_imap_module.c
--- a/src/mail/ngx_mail_imap_module.c	Tue Jan 14 12:50:51 2014 +0100
+++ b/src/mail/ngx_mail_imap_module.c	Tue Jan 14 12:51:12 2014 +0100
@@ -10,6 +10,7 @@
 #include <ngx_event.h>
 #include <ngx_mail.h>
 #include <ngx_mail_imap_module.h>
+#include <nginx.h>
 
 
 static void *ngx_mail_imap_create_srv_conf(ngx_conf_t *cf);
@@ -286,6 +287,29 @@
         size = sizeof("* ID (" CRLF) - 1;
 
         c = conf->server_ids.elts;
+
+        for (i = 1; i < conf->server_ids.nelts; i += 2) {
+
+            if (c[i].data[0] != '$')
+                continue;
+
+            switch (c[i].len)
+            {
+            case 12:
+                if (ngx_strncasecmp(c[i].data,
+                                    (u_char *) "$remote-host", 12) == 0) {
+                    conf->server_id_fields |= NGX_IMAP_ID_REMOTE_HOST;
+                }
+                break;
+            case 8:
+                if (ngx_strncasecmp(c[i].data, (u_char *) "$version", 8) == 0){
+                    c[i].data = (u_char *) NGINX_VERSION;
+                    c[i].len = sizeof(NGINX_VERSION) - 1;
+                }
+                break;
+            }
+        }
+
         for (i = 0; i < conf->server_ids.nelts; i++) {
             size += 1 + c[i].len + 2;
         }
diff -r 2d3ff21b5373 -r 147c57844b91 src/mail/ngx_mail_imap_module.h
--- a/src/mail/ngx_mail_imap_module.h	Tue Jan 14 12:50:51 2014 +0100
+++ b/src/mail/ngx_mail_imap_module.h	Tue Jan 14 12:51:12 2014 +0100
@@ -13,6 +13,9 @@
 #include <ngx_core.h>
 #include <ngx_mail.h>
 
+// Imap ID Dynamic fields
+#define NGX_IMAP_ID_REMOTE_HOST  0x0001
+#define NGX_IMAP_ID_VERSION      0x0002
 
 typedef struct {
     size_t       client_buffer_size;
@@ -21,6 +24,7 @@
     ngx_str_t    starttls_capability;
     ngx_str_t    starttls_only_capability;
     ngx_str_t    server_id;
+    ngx_uint_t   server_id_fields;
 
     ngx_uint_t   auth_methods;
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 004-ImapID_dynamicFieldValue.diff
Type: text/x-patch
Size: 4082 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20140114/b5d17493/attachment.bin>


More information about the nginx-devel mailing list