forked from sba1/simplemail
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphrase.c
113 lines (99 loc) · 3.39 KB
/
phrase.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
SimpleMail - Copyright (C) 2000 Hynek Schlawack and Sebastian Bauer
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
***************************************************************************/
/*
** phrase.c
*/
#include <stdlib.h>
#include <string.h>
#include "configuration.h"
#include "debug.h"
#include "phrase.h"
#include "support_indep.h"
/**************************************************************************
Allocates a new phrase
**************************************************************************/
struct phrase *phrase_malloc(void)
{
struct phrase *sig;
if ((sig = (struct phrase*)malloc(sizeof(struct phrase))))
{
memset(sig,0,sizeof(struct phrase));
}
return sig;
}
/**************************************************************************
Duplicates an account
**************************************************************************/
struct phrase *phrase_duplicate(struct phrase *s)
{
struct phrase *ns = phrase_malloc();
if (ns && s)
{
ns->addresses = mystrdup(s->addresses);
ns->write_welcome = mystrdup(s->write_welcome);
ns->write_welcome_repicient = mystrdup(s->write_welcome_repicient);
ns->write_closing = mystrdup(s->write_closing);
ns->reply_welcome = mystrdup(s->reply_welcome);
ns->reply_intro = mystrdup(s->reply_intro);
ns->reply_close = mystrdup(s->reply_close);
ns->forward_initial = mystrdup(s->forward_initial);
ns->forward_finish = mystrdup(s->forward_finish);
}
return ns;
}
/**************************************************************************
Frees a phrase
**************************************************************************/
void phrase_free(struct phrase *s)
{
if (!s) return;
free(s->addresses);
free(s->write_welcome);
free(s->write_welcome_repicient);
free(s->write_closing);
free(s->reply_welcome);
free(s->reply_intro);
free(s->reply_close);
free(s->forward_initial);
free(s->forward_finish);
free(s);
}
/**************************************************************************
Finds the phrase which meets the address best (actually which first fits,
expect the one which is for all).
Might return NULL!
**************************************************************************/
struct phrase *phrase_find_best(char *addr)
{
struct phrase *phrase;
struct phrase *phrase_best;
phrase = (struct phrase*)list_first(&user.config.phrase_list);
if (!addr) return phrase;
phrase_best = NULL;
while (phrase)
{
if (!phrase->addresses && !phrase_best) phrase_best = phrase;
else
{
if (mystristr(addr,phrase->addresses))
{
if (!phrase_best) phrase_best = phrase;
else if (!phrase_best->addresses) phrase_best = phrase;
}
}
phrase = (struct phrase*)node_next(&phrase->node);
}
return phrase_best;
}