talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

customheader.c (2805B)


      1 /*
      2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
      3  * Copyright (C) 1999-2022 Hiroyuki Yamamoto and the Claws Mail team
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 3 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
     17  */
     18 
     19 #include <glib.h>
     20 #include <string.h>
     21 #include <stdlib.h>
     22 
     23 #include "customheader.h"
     24 #include "utils.h"
     25 
     26 
     27 gchar *custom_header_get_str(CustomHeader *ch)
     28 {
     29 	return g_strdup_printf("%i:%s: %s",
     30 			       ch->account_id, ch->name,
     31 			       ch->value ? ch->value : "");
     32 }
     33 
     34 CustomHeader *custom_header_read_str(const gchar *buf)
     35 {
     36 	CustomHeader *ch;
     37 	gchar *account_id_str;
     38 	gint id;
     39 	gchar *name;
     40 	gchar *value;
     41 	gchar *tmp;
     42 
     43 	Xstrdup_a(tmp, buf, return NULL);
     44 
     45 	account_id_str = tmp;
     46 
     47 	name = strchr(account_id_str, ':');
     48 	if (!name)
     49 		return NULL;
     50 	else {
     51 		gchar *endp;
     52 
     53 		*name++ = '\0';
     54 		id = strtol(account_id_str, &endp, 10);
     55 		if (*endp != '\0') return NULL;
     56 	}
     57 
     58 	value = strchr(name, ':');
     59 	if (!value) return NULL;
     60 
     61 	*value++ = '\0';
     62 
     63 	g_strstrip(name);
     64 	g_strstrip(value);
     65 
     66 	ch = g_new0(CustomHeader, 1);
     67 	ch->account_id = id;
     68 	ch->name = *name ? g_strdup(name) : NULL;
     69 	ch->value = *value ? g_strdup(value) : NULL;
     70 
     71 	return ch;
     72 }
     73 
     74 CustomHeader *custom_header_find(GSList *header_list, const gchar *header)
     75 {
     76 	GSList *cur;
     77 	CustomHeader *chdr;
     78 
     79 	for (cur = header_list; cur != NULL; cur = cur->next) {
     80 		chdr = (CustomHeader *)cur->data;
     81 		if (!g_utf8_collate(chdr->name, header))
     82 			return chdr;
     83 	}
     84 
     85 	return NULL;
     86 }
     87 
     88 void custom_header_free(CustomHeader *ch)
     89 {
     90 	if (!ch) return;
     91 
     92 	g_free(ch->name);
     93 	g_free(ch->value);
     94 	g_free(ch);
     95 }
     96 
     97 gboolean custom_header_is_allowed(const gchar *header)
     98 {
     99 	if (g_ascii_strcasecmp(header, "Date")         != 0 &&
    100 	    g_ascii_strcasecmp(header, "From")         != 0 &&
    101 	    g_ascii_strcasecmp(header, "To")           != 0 &&
    102 	 /* g_ascii_strcasecmp(header, "Sender")       != 0 && */
    103 	    g_ascii_strcasecmp(header, "Message-ID")   != 0 &&
    104 	    g_ascii_strcasecmp(header, "In-Reply-To")  != 0 &&
    105 	    g_ascii_strcasecmp(header, "References")   != 0 &&
    106 	    g_ascii_strcasecmp(header, "MIME-Version") != 0 &&
    107 	    g_ascii_strcasecmp(header, "Content-Type") != 0 &&
    108 	    g_ascii_strcasecmp(header, "Content-Transfer-Encoding")
    109 	    != 0)
    110 		return TRUE;
    111 
    112 	return FALSE;
    113 }