1/*++
2/* NAME
3/*	fold_addr 3
4/* SUMMARY
5/*	address case folding
6/* SYNOPSIS
7/*	#include <fold_addr.h>
8/*
9/*	char	*fold_addr(addr, flags)
10/*	char	*addr;
11/*	int	flags;
12/* DESCRIPTION
13/*	fold_addr() case folds an address according to the options
14/*	specified with \fIflags\fR. The result value is the address
15/*	argument.
16/*
17/*	Arguments
18/* .IP addr
19/*	Null-terminated writable string with the address.
20/* .IP flags
21/*	Zero or the bit-wise OR of:
22/* .RS
23/* .IP FOLD_ADDR_USER
24/*	Case fold the address local part.
25/* .IP FOLD_ADDR_HOST
26/*	Case fold the address domain part.
27/* .IP FOLD_ADDR_ALL
28/*	Alias for (FOLD_ADDR_USER | FOLD_ADDR_HOST).
29/* .RE
30/* SEE ALSO
31/*	msg(3) diagnostics interface
32/* DIAGNOSTICS
33/*	Fatal errors: memory allocation problem.
34/* LICENSE
35/* .ad
36/* .fi
37/*	The Secure Mailer license must be distributed with this software.
38/* AUTHOR(S)
39/*	Wietse Venema
40/*	IBM T.J. Watson Research
41/*	P.O. Box 704
42/*	Yorktown Heights, NY 10598, USA
43/*--*/
44
45/* System library. */
46
47#include <sys_defs.h>
48#include <string.h>
49
50/* Utility library. */
51
52#include <stringops.h>
53
54/* Global library. */
55
56#include <fold_addr.h>
57
58/* fold_addr - case fold mail address */
59
60char   *fold_addr(char *addr, int flags)
61{
62    char   *cp;
63
64    /*
65     * Fold the address as appropriate.
66     */
67    switch (flags & FOLD_ADDR_ALL) {
68    case FOLD_ADDR_HOST:
69	if ((cp = strrchr(addr, '@')) != 0)
70	    lowercase(cp + 1);
71	break;
72    case FOLD_ADDR_USER:
73	if ((cp = strrchr(addr, '@')) != 0) {
74	    *cp = 0;
75	    lowercase(addr);
76	    *cp = '@';
77	    break;
78	}
79	/* FALLTHROUGH */
80    case FOLD_ADDR_USER | FOLD_ADDR_HOST:
81	lowercase(addr);
82	break;
83    }
84    return (addr);
85}
86