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