Home | History | Annotate | Line # | Download | only in global
      1 /*	$NetBSD: sendopts.c,v 1.3 2026/05/09 18:49:17 christos Exp $	*/
      2 
      3 /*++
      4 /* NAME
      5 /*	sendopts 3
      6 /* SUMMARY
      7 /*	Support for SMTPUTF8, REQUIRETLS, etc.
      8 /* SYNOPSIS
      9 /*	#include <sendopts.h>
     10 /*
     11 /*	const char *sendopts_strflags(
     12 /*	int	flags,
     13 /*	int	delim)
     14 /* DESCRIPTION
     15 /*	Postfix queue files and IPC messages contain a sendopts field
     16 /*	with flags that control SMTPUTF8, REQUIRETLS, etc. support. The
     17 /*	flags are documented in sendopts(3h), and are based on information
     18 /*	received with ESMTP requests or with message content.
     19 /*
     20 /*	The SMTPUTF8 flags life cycle is documented in smtputf8(3h).
     21 /*
     22 /*	sendopts_strflags() maps a sendopts flag value to printable
     23 /*	string. The result is overwritten upon each call.
     24 /*
     25 /*	Arguments:
     26 /* .IP flags
     27 /*	A bitmask that is to be converted to text.
     28 /* .IP delim
     29 /*	The character to separate output words with: one of ' ,|'.
     30 /* DIAGNOSTICS
     31 /*	Panic: invalid delimiter. Fatal error: invalid flag.
     32 /* LICENSE
     33 /* .ad
     34 /* .fi
     35 /*	The Secure Mailer license must be distributed with this software.
     36 /* AUTHOR(S)
     37 /*	Wietse Venema
     38 /*	porcupine.org
     39 /*--*/
     40 
     41 /* System library. */
     42 
     43 #include <sys_defs.h>
     44 #include <string.h>
     45 
     46  /*
     47   * Utility library.
     48   */
     49 #include <msg.h>
     50 #include <vstring.h>
     51 #include <name_mask.h>
     52 
     53  /*
     54   * Global library.
     55   */
     56 #include <sendopts.h>
     57 
     58  /*
     59   * Mapping from flags to printable string.
     60   */
     61 static NAME_MASK sendopts_flag_map[] = {
     62     "smtputf8_requested", SOPT_SMTPUTF8_REQUESTED,
     63     "smtputf8_header", SOPT_SMTPUTF8_HEADER,
     64     "smtputf8_sender", SOPT_SMTPUTF8_SENDER,
     65     "smtputf8_recipient", SOPT_SMTPUTF8_RECIPIENT,
     66     "requiretls_header", SOPT_REQUIRETLS_HEADER,
     67     "requiretls_esmtp", SOPT_REQUIRETLS_ESMTP,
     68     0,
     69 };
     70 
     71 /* sendopts_strflags - map flags code to printable string */
     72 
     73 const char *sendopts_strflags(unsigned flags, int delim)
     74 {
     75     const char myname[] = "sendopts_strflags";
     76     static const char delims[] = " ,|";
     77     static const int dflags[] = {0, NAME_MASK_COMMA, NAME_MASK_PIPE};
     78     static VSTRING *result;
     79     const char *cp;
     80 
     81     if (flags == 0)
     82 	return ("none");
     83 
     84     if (result == 0)
     85 	result = vstring_alloc(20);
     86     else
     87 	VSTRING_RESET(result);
     88 
     89     if ((cp = strchr(delims, delim)) == 0)
     90 	msg_panic("%s: bad delimiter: '%c'", myname, delim);
     91 
     92     return (str_name_mask_opt(result, "sendopts_strflags", sendopts_flag_map,
     93 			      flags, NAME_MASK_FATAL | dflags[cp - delims]));
     94 }
     95