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


Miscellaneous functions.  


\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
def \textbf{ addr2bin} (s)
\item 
def \textbf{ bin2long6} (s)
\item 
\mbox{\label{namespaceMilter_1_1utils_a0ab12c35a7b44f0663b327762130a061}} 
def {\bfseries inet\+\_\+ntop} (s)
\item 
\mbox{\label{namespaceMilter_1_1utils_acaa8e9a501de5014cfea4679694364f2}} 
def {\bfseries inet\+\_\+pton} (s)
\item 
\mbox{\label{namespaceMilter_1_1utils_a6455f65e1f49c574ad13ab434b60fe75}} 
def {\bfseries cidr} (i, n, mask=MASK)
\item 
def \textbf{ iniplist} (ipaddr, iplist)
\item 
def \textbf{ parseaddr} (t)
\begin{DoxyCompactList}\small\item\em Split email into Fullname and address. \end{DoxyCompactList}\item 
\mbox{\label{namespaceMilter_1_1utils_a51e91db3746f6d58ecf34415c48005cb}} 
def \textbf{ decode} (s, convert\+\_\+eols=None)
\begin{DoxyCompactList}\small\item\em Fix email.\+base64mime.\+decode to add any missing padding. \end{DoxyCompactList}\item 
def \textbf{ parse\+\_\+addr} (t)
\item 
def \textbf{ parse\+\_\+header} (val)
\begin{DoxyCompactList}\small\item\em Decode headers gratuitously encoded to hide the content. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\label{namespaceMilter_1_1utils_af056a814fbb2772155cd900b43d04480}} 
{\bfseries dnsre} = re.\+compile(r\textquotesingle{}$^\wedge$[a-\/z][-\/a-\/z\textbackslash{}d.]+\$\textquotesingle{}, re.\+IGNORECASE)
\item 
\mbox{\label{namespaceMilter_1_1utils_ae4a17f563a8b9249dbbaa71cae1e53ba}} 
string {\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 
\mbox{\label{namespaceMilter_1_1utils_a55707307bd64817338430a571a99fd24}} 
{\bfseries ip4re} = re.\+compile(PAT\+\_\+\+IP4+\textquotesingle{}\$\textquotesingle{})
\item 
{\bfseries ip6re}
\item 
\mbox{\label{namespaceMilter_1_1utils_a94942e91f59e9aa64e5a9b656eb81623}} 
int {\bfseries MASK} = 0x\+FFFFFFFF
\item 
\mbox{\label{namespaceMilter_1_1utils_a79b183c5ad99eef23cefc546b28c5c06}} 
int {\bfseries MASK6} = 0x\+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Miscellaneous functions. 

\doxysubsection{Function Documentation}
\mbox{\label{namespaceMilter_1_1utils_affe21c3e74caa9bc400dcdd7e53b2bb4}} 
\index{Milter.utils@{Milter.utils}!addr2bin@{addr2bin}}
\index{addr2bin@{addr2bin}!Milter.utils@{Milter.utils}}
\doxysubsubsection{addr2bin()}
{\footnotesize\ttfamily def Milter.\+utils.\+addr2bin (\begin{DoxyParamCaption}\item[{}]{s }\end{DoxyParamCaption})}

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

References Milter.\+utils.\+bin2long6().



Referenced by Milter.\+utils.\+iniplist().

\mbox{\label{namespaceMilter_1_1utils_a00ed0aa471a9440c0f466ec080ce911f}} 
\index{Milter.utils@{Milter.utils}!bin2long6@{bin2long6}}
\index{bin2long6@{bin2long6}!Milter.utils@{Milter.utils}}
\doxysubsubsection{bin2long6()}
{\footnotesize\ttfamily def 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 Milter.\+utils.\+addr2bin(), and Milter.\+utils.\+iniplist().

\mbox{\label{namespaceMilter_1_1utils_a6a4fc23c7b9dd3fb561e447d0d6caa6d}} 
\index{Milter.utils@{Milter.utils}!iniplist@{iniplist}}
\index{iniplist@{iniplist}!Milter.utils@{Milter.utils}}
\doxysubsubsection{iniplist()}
{\footnotesize\ttfamily def 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 Milter.\+utils.\+addr2bin(), and Milter.\+utils.\+bin2long6().

\mbox{\label{namespaceMilter_1_1utils_a11d48fae3c0d632f511596d32197c7ec}} 
\index{Milter.utils@{Milter.utils}!parse\_addr@{parse\_addr}}
\index{parse\_addr@{parse\_addr}!Milter.utils@{Milter.utils}}
\doxysubsubsection{parse\_addr()}
{\footnotesize\ttfamily def 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}
 \mbox{\label{namespaceMilter_1_1utils_a09c39d357768b4e865de913f781160a6}} 
\index{Milter.utils@{Milter.utils}!parse\_header@{parse\_header}}
\index{parse\_header@{parse\_header}!Milter.utils@{Milter.utils}}
\doxysubsubsection{parse\_header()}
{\footnotesize\ttfamily def 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}
 \mbox{\label{namespaceMilter_1_1utils_acca0fec60a6159394be76f480d3aa639}} 
\index{Milter.utils@{Milter.utils}!parseaddr@{parseaddr}}
\index{parseaddr@{parseaddr}!Milter.utils@{Milter.utils}}
\doxysubsubsection{parseaddr()}
{\footnotesize\ttfamily def 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}
 

\doxysubsection{Variable Documentation}
\mbox{\label{namespaceMilter_1_1utils_aa299e0b94e99635995bbd0ab97b57800}} 
\index{Milter.utils@{Milter.utils}!ip6re@{ip6re}}
\index{ip6re@{ip6re}!Milter.utils@{Milter.utils}}
\doxysubsubsection{ip6re}
{\footnotesize\ttfamily Milter.\+utils.\+ip6re}

{\bfseries Initial value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 =  re.compile(                 \textcolor{stringliteral}{'(?:\%(hex4)s:)\{6\}\%(ls32)s\$'}}
\DoxyCodeLine{2                    \textcolor{stringliteral}{'|::(?:\%(hex4)s:)\{5\}\%(ls32)s\$'}}
\DoxyCodeLine{3                   \textcolor{stringliteral}{'|(?:\%(hex4)s)?::(?:\%(hex4)s:)\{4\}\%(ls32)s\$'}}
\DoxyCodeLine{4     \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,1\}\%(hex4)s)?::(?:\%(hex4)s:)\{3\}\%(ls32)s\$'}}
\DoxyCodeLine{5     \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,2\}\%(hex4)s)?::(?:\%(hex4)s:)\{2\}\%(ls32)s\$'}}
\DoxyCodeLine{6     \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,3\}\%(hex4)s)?::\%(hex4)s:\%(ls32)s\$'}}
\DoxyCodeLine{7     \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,4\}\%(hex4)s)?::\%(ls32)s\$'}}
\DoxyCodeLine{8     \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,5\}\%(hex4)s)?::\%(hex4)s\$'}}
\DoxyCodeLine{9     \textcolor{stringliteral}{'|(?:(?:\%(hex4)s:)\{0,6\}\%(hex4)s)?::\$'}}
\DoxyCodeLine{10   \% \{}
\DoxyCodeLine{11     \textcolor{stringliteral}{'ls32'}: \textcolor{stringliteral}{r'(?:[0-\/9a-\/f]\{1,4\}:[0-\/9a-\/f]\{1,4\}|\%s)'}\%PAT\_IP4,}
\DoxyCodeLine{12     \textcolor{stringliteral}{'hex4'}: \textcolor{stringliteral}{r'[0-\/9a-\/f]\{1,4\}'}}
\DoxyCodeLine{13     \}, re.IGNORECASE)}

\end{DoxyCode}
