summaryrefslogtreecommitdiffstats
path: root/src/global/info_log_addr_form.c
blob: cbe3920e601b468d91a969fe258f327cd33ee45f (plain)
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
114
115
116
117
118
119
120
121
122
123
124
/*++
/* NAME
/*	info_log_addr_form 3
/* SUMMARY
/*	format internal-form information for info logging
/* SYNOPSIS
/*	#include <info_log_addr_form.h>
/*
/*	const char *info_log_addr_form_recipient(
/*	const char *recipient_addr)
/*
/*	const char *info_log_addr_form_sender_addr(
/*	const char *sender_addr)
/* DESCRIPTION
/*	info_log_addr_form_recipient() and info_log_addr_form_sender_addr()
/*	format an internal-form recipient or sender email address
/*	for non-debug logging. Each function has its own private
/*	buffer. Each call overwrites the result from a previous call.
/*
/*	Note: the empty address is passed unchanged; it is not
/*	formatted as "".
/* .IP recipient_addr
/* .IP *sender_addr
/*	An internal-form email address.
/* LICENSE
/* .ad
/* .fi
/*	The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/*	Wietse Venema
/*	Google, Inc.
/*	111 8th Avenue
/*	New York, NY 10011, USA
/*--*/

 /*
  * System library.
  */
#include <sys_defs.h>

 /*
  * Utility library.
  */
#include <msg.h>
#include <name_code.h>
#include <vstring.h>

 /*
  * Global library.
  */
#include <info_log_addr_form.h>
#include <mail_addr_form.h>
#include <mail_params.h>
#include <quote_822_local.h>

#define INFO_LOG_ADDR_FORM_VAL_NOT_SET	0
#define INFO_LOG_ADDR_FORM_VAL_INTERNAL	1
#define INFO_LOG_ADDR_FORM_VAL_EXTERNAL	2

/* Format for info logging. */

int     info_log_addr_form_form = INFO_LOG_ADDR_FORM_VAL_NOT_SET;

#define STR(x)	vstring_str(x)

/* info_log_addr_form_init - one-time initialization */

static void info_log_addr_form_init(void)
{
    static NAME_CODE info_log_addr_form_table[] = {
	INFO_LOG_ADDR_FORM_NAME_EXTERNAL, INFO_LOG_ADDR_FORM_VAL_EXTERNAL,
	INFO_LOG_ADDR_FORM_NAME_INTERNAL, INFO_LOG_ADDR_FORM_VAL_INTERNAL,
	0, INFO_LOG_ADDR_FORM_VAL_NOT_SET,
    };
    info_log_addr_form_form = name_code(info_log_addr_form_table,
					NAME_CODE_FLAG_NONE,
					var_info_log_addr_form);

    if (info_log_addr_form_form == INFO_LOG_ADDR_FORM_VAL_NOT_SET)
	msg_fatal("invalid parameter setting \"%s = %s\"",
		  VAR_INFO_LOG_ADDR_FORM, var_info_log_addr_form);
}

/* info_log_addr_form - format an email address for info logging */

static VSTRING *info_log_addr_form(VSTRING *buf, const char *addr)
{
    const char myname[] = "info_log_addr_form";

    if (buf == 0)
	buf = vstring_alloc(100);
    if (info_log_addr_form_form == INFO_LOG_ADDR_FORM_VAL_NOT_SET)
	info_log_addr_form_init();
    if (*addr == 0
	|| info_log_addr_form_form == INFO_LOG_ADDR_FORM_VAL_INTERNAL) {
	vstring_strcpy(buf, addr);
    } else if (info_log_addr_form_form == INFO_LOG_ADDR_FORM_VAL_EXTERNAL) {
	quote_822_local(buf, addr);
    } else {
	msg_panic("%s: bad format type: %d",
		  myname, info_log_addr_form_form);
    }
    return (buf);
}

/* info_log_addr_form_recipient - format a recipient address for info logging */

const char *info_log_addr_form_recipient(const char *recipient_addr)
{
    static VSTRING *recipient_buffer = 0;

    recipient_buffer = info_log_addr_form(recipient_buffer, recipient_addr);
    return (STR(recipient_buffer));
}

/* info_log_addr_form_sender - format a sender address for info logging */

const char *info_log_addr_form_sender(const char *sender_addr)
{
    static VSTRING *sender_buffer = 0;

    sender_buffer = info_log_addr_form(sender_buffer, sender_addr);
    return (STR(sender_buffer));
}