\doxysection{Milter.\+utils Namespace Reference}
\label{namespaceMilter_1_1utils}\index{Milter.utils@{Milter.utils}}


Miscellaneous functions.  


\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\textbf{ addr2bin} (s)
\item 
\textbf{ bin2long6} (s)
\item 
\label{namespaceMilter_1_1utils_a65cd071ab76b873dbf40454ac4fda027} 
{\bfseries inet\+\_\+ntop} (s)
\item 
\label{namespaceMilter_1_1utils_a285ad2813e0a79470af66af6c7a24689} 
{\bfseries inet\+\_\+pton} (s)
\item 
\label{namespaceMilter_1_1utils_a1587d3f0fae965ef641f97366f468a6d} 
{\bfseries cidr} (i, n, mask=MASK)
\item 
\textbf{ iniplist} (ipaddr, iplist)
\item 
\textbf{ parseaddr} (t)
\begin{DoxyCompactList}\small\item\em Split email into Fullname and address. \end{DoxyCompactList}\item 
\label{namespaceMilter_1_1utils_aa4ba1e9cbdc3f8e1aa146be3ba060bfc} 
{\bfseries decode} (s, convert\+\_\+eols=None)
\begin{DoxyCompactList}\small\item\em Fix email.\+base64mime.\+decode to add any missing padding. \end{DoxyCompactList}\item 
\textbf{ parse\+\_\+addr} (t)
\item 
\textbf{ parse\+\_\+header} (val)
\begin{DoxyCompactList}\small\item\em Decode headers gratuitously encoded to hide the content. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\label{namespaceMilter_1_1utils_af056a814fbb2772155cd900b43d04480} 
{\bfseries dnsre} = re.\+compile(r\textquotesingle{}$^\wedge$[a-\/z][-\/a-\/z\textbackslash{}d.]+\$\textquotesingle{}, re.\+IGNORECASE)
\item 
\label{namespaceMilter_1_1utils_a6f4b213b741538f6542ca19ab42aa76f} 
str {\bfseries PAT\+\_\+\+IP4} = r\textquotesingle{}\textbackslash{}.\textquotesingle{}.join([r\textquotesingle{}(?\+:\textbackslash{}d$\vert$[1-\/9]\textbackslash{}d$\vert$1\textbackslash{}d\textbackslash{}d$\vert$2[0-\/4]\textbackslash{}d$\vert$25[0-\/5])\textquotesingle{}]$\ast$4)
\item 
\label{namespaceMilter_1_1utils_a55707307bd64817338430a571a99fd24} 
{\bfseries ip4re} = re.\+compile(PAT\+\_\+\+IP4+\textquotesingle{}\$\textquotesingle{})
\item 
\textbf{ ip6re}
\item 
\label{namespaceMilter_1_1utils_a94942e91f59e9aa64e5a9b656eb81623} 
int {\bfseries MASK} = 0x\+FFFFFFFF
\item 
\label{namespaceMilter_1_1utils_a79b183c5ad99eef23cefc546b28c5c06} 
int {\bfseries MASK6} = 0x\+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
\item 
\label{namespaceMilter_1_1utils_a62b37bdc2f2d1b10e59f3af712738cc8} 
{\bfseries decode}
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Miscellaneous functions. 

\label{doc-func-members}
\doxysubsection{Function Documentation}
\index{Milter.utils@{Milter.utils}!addr2bin@{addr2bin}}
\index{addr2bin@{addr2bin}!Milter.utils@{Milter.utils}}
\doxysubsubsection{addr2bin()}
{\footnotesize\ttfamily \label{namespaceMilter_1_1utils_a6c2f6541abec1e3e4da11845224ca843} 
Milter.\+utils.\+addr2bin (\begin{DoxyParamCaption}\item[{}]{s}{}\end{DoxyParamCaption})}

\begin{DoxyVerb}Convert a string IPv4 address into an unsigned integer.\end{DoxyVerb}
 

References \textbf{ bin2long6()}.



Referenced by \textbf{ iniplist()}.

\index{Milter.utils@{Milter.utils}!bin2long6@{bin2long6}}
\index{bin2long6@{bin2long6}!Milter.utils@{Milter.utils}}
\doxysubsubsection{bin2long6()}
{\footnotesize\ttfamily \label{namespaceMilter_1_1utils_a5212cae45cbe3fe29c2f25324b824c38} 
Milter.\+utils.\+bin2long6 (\begin{DoxyParamCaption}\item[{}]{s}{}\end{DoxyParamCaption})}

\begin{DoxyVerb}Convert binary IP6 address into an unsigned Python long integer.\end{DoxyVerb}
 

Referenced by \textbf{ addr2bin()}, and \textbf{ iniplist()}.

\index{Milter.utils@{Milter.utils}!iniplist@{iniplist}}
\index{iniplist@{iniplist}!Milter.utils@{Milter.utils}}
\doxysubsubsection{iniplist()}
{\footnotesize\ttfamily \label{namespaceMilter_1_1utils_a38a92094ecf995e5d3394549f9416fcf} 
Milter.\+utils.\+iniplist (\begin{DoxyParamCaption}\item[{}]{ipaddr}{, }\item[{}]{iplist}{}\end{DoxyParamCaption})}

\begin{DoxyVerb}Return whether ip is in cidr list
>>> iniplist('66.179.26.146',['127.0.0.1','66.179.26.128/26'])
True
>>> iniplist('127.0.0.1',['127.0.0.1','66.179.26.128/26'])
True
>>> iniplist('192.168.0.45',['192.168.0.*'])
True
>>> iniplist('4.2.2.2',['b.resolvers.Level3.net'])
True
>>> iniplist('2606:2800:220:1::',['example.com/40'])
True
>>> iniplist('4.2.2.2',['nothing.example.com'])
False
>>> iniplist('2001:610:779:0:223:6cff:fe9a:9cf3',['127.0.0.1','172.20.1.0/24','2001:610:779::/48'])
True
>>> iniplist('2G01:610:779:0:223:6cff:fe9a:9cf3',['127.0.0.1','172.20.1.0/24','2001:610:779::/48'])
Traceback (most recent call last):
  ...
ValueError: Invalid ip syntax:2G01:610:779:0:223:6cff:fe9a:9cf3
\end{DoxyVerb}
 

References \textbf{ addr2bin()}, \textbf{ bin2long6()}, and \textbf{ iniplist()}.



Referenced by \textbf{ iniplist()}.

\index{Milter.utils@{Milter.utils}!parse\_addr@{parse\_addr}}
\index{parse\_addr@{parse\_addr}!Milter.utils@{Milter.utils}}
\doxysubsubsection{parse\_addr()}
{\footnotesize\ttfamily \label{namespaceMilter_1_1utils_a23c1a5233c7f31541278f399415af526} 
Milter.\+utils.\+parse\+\_\+addr (\begin{DoxyParamCaption}\item[{}]{t}{}\end{DoxyParamCaption})}

\begin{DoxyVerb}Split email into user,domain.

>>> parse_addr('user@example.com')
['user', 'example.com']
>>> parse_addr('"user@example.com"')
['user@example.com']
>>> parse_addr('"user@bar"@example.com')
['user@bar', 'example.com']
>>> parse_addr('foo')
['foo']
>>> parse_addr('@mx.example.com:user@example.com')
['user', 'example.com']
>>> parse_addr('@user@example.com')
['@user', 'example.com']
\end{DoxyVerb}
 \index{Milter.utils@{Milter.utils}!parse\_header@{parse\_header}}
\index{parse\_header@{parse\_header}!Milter.utils@{Milter.utils}}
\doxysubsubsection{parse\_header()}
{\footnotesize\ttfamily \label{namespaceMilter_1_1utils_a3e22917d8e7016b36c3caabadb1b18ac} 
Milter.\+utils.\+parse\+\_\+header (\begin{DoxyParamCaption}\item[{}]{val}{}\end{DoxyParamCaption})}



Decode headers gratuitously encoded to hide the content. 

Spammers often encode headers to obscure the content from spam filters. This function decodes gratuitously encoded headers. 
\begin{DoxyParams}{Parameters}
{\em val} & the raw header value \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the decoded value or the original raw value
\end{DoxyReturn}
\begin{DoxyVerb}Decode headers gratuitously encoded to hide the content.
\end{DoxyVerb}
 \index{Milter.utils@{Milter.utils}!parseaddr@{parseaddr}}
\index{parseaddr@{parseaddr}!Milter.utils@{Milter.utils}}
\doxysubsubsection{parseaddr()}
{\footnotesize\ttfamily \label{namespaceMilter_1_1utils_afc010ce396140155d037d471347131e4} 
Milter.\+utils.\+parseaddr (\begin{DoxyParamCaption}\item[{}]{t}{}\end{DoxyParamCaption})}



Split email into Fullname and address. 

This replaces {\ttfamily email.\+utils.\+parseaddr} but fixes some {\texttt{tricky test cases}}. Additional tricky cases are still broken. Patches welcome.

\begin{DoxyVerb}Split email into Fullname and address.

>>> parseaddr('user@example.com')
('', 'user@example.com')
>>> parseaddr('"Full Name" <foo@example.com>')
('Full Name', 'foo@example.com')
>>> parseaddr('spam@spammer.com <foo@example.com>')
('spam@spammer.com', 'foo@example.com')
>>> parseaddr('God@heaven <@hop1.org,@hop2.net:jeff@spec.org>')
('God@heaven', 'jeff@spec.org')
>>> parseaddr('Real Name ((comment)) <addr...@example.com>')
('Real Name (comment)', 'addr...@example.com')
\end{DoxyVerb}
 

\label{doc-var-members}
\doxysubsection{Variable Documentation}
\index{Milter.utils@{Milter.utils}!ip6re@{ip6re}}
\index{ip6re@{ip6re}!Milter.utils@{Milter.utils}}
\doxysubsubsection{ip6re}
{\footnotesize\ttfamily \label{namespaceMilter_1_1utils_aa299e0b94e99635995bbd0ab97b57800} 
Milter.\+utils.\+ip6re}

{\bfseries Initial value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ =\ \ re.compile(\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{'(?:\%(hex4)s:)\{6\}\%(ls32)s\$'}}
\DoxyCodeLine{00002\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{'|::(?:\%(hex4)s:)\{5\}\%(ls32)s\$'}}
\DoxyCodeLine{00003\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{'|(?:\%(hex4)s)?::(?:\%(hex4)s:)\{4\}\%(ls32)s\$'}}
\DoxyCodeLine{00004\ \ \ \ \ \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,1\}\%(hex4)s)?::(?:\%(hex4)s:)\{3\}\%(ls32)s\$'}}
\DoxyCodeLine{00005\ \ \ \ \ \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,2\}\%(hex4)s)?::(?:\%(hex4)s:)\{2\}\%(ls32)s\$'}}
\DoxyCodeLine{00006\ \ \ \ \ \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,3\}\%(hex4)s)?::\%(hex4)s:\%(ls32)s\$'}}
\DoxyCodeLine{00007\ \ \ \ \ \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,4\}\%(hex4)s)?::\%(ls32)s\$'}}
\DoxyCodeLine{00008\ \ \ \ \ \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,5\}\%(hex4)s)?::\%(hex4)s\$'}}
\DoxyCodeLine{00009\ \ \ \ \ \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,6\}\%(hex4)s)?::\$'}}
\DoxyCodeLine{00010\ \ \ \%\ \{}
\DoxyCodeLine{00011\ \ \ \ \ \textcolor{stringliteral}{'ls32'}:\ \textcolor{stringliteral}{r'(?:[0-\/9a-\/f]\{1,4\}:[0-\/9a-\/f]\{1,4\}|\%s)'}\%PAT\_IP4,}
\DoxyCodeLine{00012\ \ \ \ \ \textcolor{stringliteral}{'hex4'}:\ \textcolor{stringliteral}{r'[0-\/9a-\/f]\{1,4\}'}}
\DoxyCodeLine{00013\ \ \ \ \ \},\ re.IGNORECASE)}

\end{DoxyCode}
