Инструменты пользователя

Инструменты сайта


soft:msmtp:dobavlenie_podderzhki_psevdonimov_otpravitelej

Добавление поддержки псевдонимов отправителей

После использования патча станосится возможным в msmtprc добавлять для учётных записей (и глобально) псевдонимы адресов отправителей в формате:

aliases псевдоним>реальный_адрес;[псевдоним>реальный_адрес;...]

Например, у меня есть такая настройка:

aliases root>hostmaster@atdl.ru; postmaster>postmaster@atdl.ru;
diff -ru msmtp-1.4.7.orig/src/conf.c msmtp-1.4.7/src/conf.c
--- msmtp-1.4.7.orig/src/conf.c    2009-04-10 12:12:23.000000000 +0400
+++ msmtp-1.4.7/src/conf.c    2009-04-10 12:12:56.000000000 +0400
@@ -70,6 +70,7 @@
     a->dsn_return = NULL;
     a->dsn_notify = NULL;
     a->keepbcc = 0;
+    a->aliases = NULL;
     a->auth_mech = NULL;
     a->username = NULL;
     a->password = NULL;
@@ -114,6 +115,7 @@
     a->dsn_return = acc->dsn_return ? xstrdup(acc->dsn_return) : NULL;
     a->dsn_notify = acc->dsn_notify ? xstrdup(acc->dsn_notify) : NULL;
     a->keepbcc = acc->keepbcc;
+    a->aliases = acc->aliases ? xstrdup(acc->aliases) : NULL;
     a->auth_mech = acc->auth_mech ? xstrdup(acc->auth_mech) : NULL;
     a->username = acc->username ? xstrdup(acc->username) : NULL;
     a->password = acc->password ? xstrdup(acc->password) : NULL;
@@ -151,6 +153,7 @@
     free(p->domain);
     free(p->from);
     free(p->maildomain);
+    free(p->aliases);
     free(p->auth_mech);
     free(p->username);
     free(p->password);
@@ -440,6 +443,11 @@
     free(acc1->maildomain);
     acc1->maildomain = acc2->maildomain ? xstrdup(acc2->maildomain) : NULL;
     }
+    if (acc2->mask & ACC_ALIASES)
+    {
+    free(acc1->aliases);
+    acc1->aliases = acc2->aliases ? xstrdup(acc2->aliases) : NULL;
+    }
     if (acc2->mask & ACC_AUTH_MECH)
     {
     free(acc1->auth_mech);
@@ -1036,6 +1044,12 @@
         free(acc->maildomain);
         acc->maildomain = xstrdup(arg);
     }
+    else if (strcmp(cmd, "aliases") == 0)
+    {
+        acc->mask |= ACC_ALIASES;
+        free(acc->aliases);
+        acc->aliases = xstrdup(arg);
+    }
     else if (strcmp(cmd, "auth") == 0)
     {
         acc->mask |= ACC_AUTH_MECH;
diff -ru msmtp-1.4.7.orig/src/conf.h msmtp-1.4.7/src/conf.h
--- msmtp-1.4.7.orig/src/conf.h    2009-04-10 12:12:23.000000000 +0400
+++ msmtp-1.4.7/src/conf.h    2009-04-10 12:12:56.000000000 +0400
@@ -67,6 +67,7 @@
 #define ACC_TLS_FORCE_SSLV3    (1 << 21)
 #define ACC_LOGFILE        (1 << 22)
 #define ACC_SYSLOG        (1 << 23)
+#define ACC_ALIASES        (1 << 24)

 typedef struct
 {
@@ -87,6 +88,8 @@
     char *from;            /* envelope from address */
     char *maildomain;        /* the domain part of generated envelope from
                    addresses */
+    char *aliases;        /* aliases of recipients in form
+                   user>remote_user[;user>remote_user...] */
     char *dsn_return;        /* DSN return request */
     char *dsn_notify;        /* DSN notify request */
     int keepbcc;        /* flag: keep the Bcc header in the mail? */
diff -ru msmtp-1.4.7.orig/src/msmtp.c msmtp-1.4.7/src/msmtp.c
--- msmtp-1.4.7.orig/src/msmtp.c    2009-04-10 12:12:23.000000000 +0400
+++ msmtp-1.4.7/src/msmtp.c    2009-04-10 12:13:23.000000000 +0400
@@ -1364,6 +1364,44 @@
         goto error_exit;
     }
     }
+
+    /* Resolving recipients aliases */
+    if (acc->aliases)
+    {
+    list_t *l;
+    char alias[256];
+    char recipient[256];
+        char *p, *c;
+        for (p=acc->aliases; *p>=32; p++)
+        {
+            memset(alias, 0, sizeof(alias));
+            memset(recipient, 0, sizeof(recipient));
+            while(*p && (*p==';' || *p==' ')) p++;
+            for (c=p; *p>32 && *p!=';'; p++)
+            {
+            if (*p=='>')
+            {
+                strncpy(alias, c, p - c);
+                c = p + 1;
+            }
+            }
+            if (*alias) strncpy(recipient, c, p - c);
+            if (*recipient)
+            {
+            l = recipients;
+            while(!list_is_empty(l))
+            {
+                l = l->next;
+                if (l->data && !strcasecmp(l->data, alias))
+                {
+                free(l->data);
+                l->data = xstrdup(recipient);
+                }
+            }
+            }
+        }
+    }
+
     /* create a new smtp_server_t */
     srv = smtp_new(debug ? stdout : NULL, acc->protocol);

@@ -2989,6 +3027,7 @@
     printf("auto_from       = %s\n"
         "maildomain      = %s\n"
         "from            = %s\n"
+        "aliases         = %s\n"
         "dsn_notify      = %s\n"
         "dsn_return      = %s\n"
         "keepbcc         = %s\n"
@@ -2997,6 +3036,7 @@
         account->auto_from ? _("on") : _("off"),
         account->maildomain ? account->maildomain : _("(not set)"),
         account->from ? account->from : _("(not set)"),
+        account->aliases ? account->aliases : _("(not set)"),
         account->dsn_notify ? account->dsn_notify : _("(not set)"),
         account->dsn_return ? account->dsn_return : _("(not set)"),
         account->keepbcc ? _("on") : _("off"),

Дискуссия

Enter your comment
 
soft/msmtp/dobavlenie_podderzhki_psevdonimov_otpravitelej.txt · Последние изменения: 16.11.2009 20:26 (внешнее изменение)

Инструменты страницы