masqmail-0.2

diff src/rewrite.c @ 0:08114f7dcc23

this is masqmail-0.2.21 from oliver kurth
author meillo@marmaro.de
date Fri, 26 Sep 2008 17:05:23 +0200
parents
children 26e34ae9a3e3
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/rewrite.c	Fri Sep 26 17:05:23 2008 +0200
     1.3 @@ -0,0 +1,100 @@
     1.4 +/*  MasqMail
     1.5 +    Copyright (C) 1999-2001 Oliver Kurth
     1.6 +
     1.7 +    This program is free software; you can redistribute it and/or modify
     1.8 +    it under the terms of the GNU General Public License as published by
     1.9 +    the Free Software Foundation; either version 2 of the License, or
    1.10 +    (at your option) any later version.
    1.11 +
    1.12 +    This program is distributed in the hope that it will be useful,
    1.13 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 +    GNU General Public License for more details.
    1.16 +
    1.17 +    You should have received a copy of the GNU General Public License
    1.18 +    along with this program; if not, write to the Free Software
    1.19 +    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    1.20 +*/
    1.21 +
    1.22 +#ifndef REWRITE_TEST
    1.23 +#include "masqmail.h"
    1.24 +#endif
    1.25 +
    1.26 +gboolean set_address_header_domain(header *hdr, gchar *domain)
    1.27 +{
    1.28 +  gchar *p = hdr->value;
    1.29 +  gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
    1.30 +  gint tmp;
    1.31 +
    1.32 +  while(*p){
    1.33 +    gchar *loc_beg, *loc_end;
    1.34 +    gchar *dom_beg, *dom_end;
    1.35 +    gchar *addr_end;
    1.36 +    gchar *rewr_string;
    1.37 +
    1.38 +    if(parse_address_rfc822(p,
    1.39 +			    &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)){
    1.40 +      gchar *left, *right;
    1.41 +
    1.42 +      if(dom_beg != NULL){
    1.43 +	left = g_strndup(p, dom_beg - p);
    1.44 +	right = g_strndup(dom_end, addr_end - dom_end);
    1.45 +
    1.46 +	rewr_string = g_strconcat(left, domain, right, NULL);
    1.47 +      }else{
    1.48 +	left = g_strndup(p, loc_end - p);
    1.49 +	right = g_strndup(loc_end, addr_end - loc_end);
    1.50 +
    1.51 +	rewr_string = g_strconcat(left, "@", domain, right, NULL);
    1.52 +      }
    1.53 +      g_free(left);
    1.54 +      g_free(right);
    1.55 +
    1.56 +      p = addr_end;
    1.57 +      if(*p == ',') p++;
    1.58 +
    1.59 +      new_hdr =
    1.60 +	g_strconcat(new_hdr, rewr_string,
    1.61 +		    *p != 0 ? "," : NULL, NULL);
    1.62 +
    1.63 +    }else
    1.64 +      return FALSE;
    1.65 +  }
    1.66 +  tmp = (hdr->value - hdr->header);
    1.67 +  g_free(hdr->header);
    1.68 +  hdr->header = new_hdr;
    1.69 +  hdr->value = hdr->header + tmp;
    1.70 +
    1.71 +  return TRUE;
    1.72 +}
    1.73 +
    1.74 +gboolean map_address_header(header *hdr, GList *table)
    1.75 +{
    1.76 +  GList *addr_list = addr_list_append_rfc822(NULL, hdr->value, conf.host_name);
    1.77 +  GList *addr_node;
    1.78 +  gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
    1.79 +  gboolean did_change = FALSE;
    1.80 +
    1.81 +  foreach(addr_list, addr_node){
    1.82 +    address *addr = (address *)(addr_node->data);
    1.83 +    gchar *rewr_string = (gchar *)table_find_fnmatch(table, addr->local_part);
    1.84 +
    1.85 +    if(rewr_string == NULL)
    1.86 +      rewr_string = addr->address;
    1.87 +    else
    1.88 +      did_change = TRUE;
    1.89 +
    1.90 +    if(rewr_string)
    1.91 +      new_hdr =
    1.92 +	g_strconcat(new_hdr, rewr_string,
    1.93 +		    g_list_next(addr_node) ? "," : "\n", NULL);
    1.94 +  }
    1.95 +  if(did_change){
    1.96 +    g_free(hdr->header);
    1.97 +    hdr->header = new_hdr;
    1.98 +  }else
    1.99 +    g_free(new_hdr);
   1.100 +
   1.101 +  return did_change;
   1.102 +}
   1.103 +