Mercurial > masqmail
view src/rewrite.c @ 340:60bb2dbe2866 0.3.3
In the tests: replaced logname(1) with $LOGNAME
Because logname(1) may not work if it has no controlling terminal.
See: http://aplawrence.com/cgi-bin/printer.pl?arg=/Forum/TonyLawrence8.html
Be it that reason or not, it didn't work on Crux, but $LOGNAME is set.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Wed, 31 Aug 2011 09:14:38 +0200 |
parents | 681863fdafbb |
children | 41958685480d |
line wrap: on
line source
/* MasqMail Copyright (C) 1999-2001 Oliver Kurth This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef REWRITE_TEST #include "masqmail.h" #endif gboolean set_address_header_domain(header * hdr, gchar * domain) { gchar *p = hdr->value; gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header); gint tmp; gchar *loc_beg, *loc_end; gchar *dom_beg, *dom_end; gchar *addr_end; gchar *rewr_string; gchar *left, *right; while (*p) { if (!parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) { return FALSE; } if (dom_beg) { left = g_strndup(p, dom_beg - p); right = g_strndup(dom_end, addr_end - dom_end); rewr_string = g_strconcat(left, domain, right, NULL); } else { left = g_strndup(p, loc_end - p); right = g_strndup(loc_end, addr_end - loc_end); rewr_string = g_strconcat(left, "@", domain, right, NULL); } g_free(left); g_free(right); p = addr_end; if (*p == ',') { p++; } new_hdr = g_strconcat(new_hdr, rewr_string, *p != '\0' ? "," : NULL, NULL); } tmp = (hdr->value - hdr->header); g_free(hdr->header); hdr->header = new_hdr; hdr->value = hdr->header + tmp; return TRUE; } gboolean map_address_header(header * hdr, GList * table) { GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name); GList *addr_node; gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header); gboolean did_change = FALSE; foreach(addr_list, addr_node) { address *addr = (address *) (addr_node->data); gchar *rewr_string = (gchar *) table_find_fnmatch(table, addr->local_part); if (rewr_string) { did_change = TRUE; } else { rewr_string = addr->address; } if (rewr_string) { new_hdr = g_strconcat(new_hdr, rewr_string, g_list_next(addr_node) ? "," : "\n", NULL); } } if (did_change) { g_free(hdr->header); hdr->header = new_hdr; } else { g_free(new_hdr); } return did_change; }