\section{Milter.\-utils Namespace Reference}
\label{namespaceMilter_1_1utils}\index{Milter.\-utils@{Milter.\-utils}}


Miscellaneous functions.  


\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
def {\bf addr2bin}
\item 
def {\bf bin2long6}
\item 
def {\bfseries inet\-\_\-ntop}\label{namespaceMilter_1_1utils_ae39e3f02048b79e37449cadc94dd9590}

\item 
def {\bfseries inet\-\_\-pton}\label{namespaceMilter_1_1utils_a015df055ebf7875f029bfa5e986bf505}

\item 
def {\bfseries cidr}\label{namespaceMilter_1_1utils_adf2ddc4a0d7ea2d2dcf9e1ebcfae66ee}

\item 
def {\bf iniplist}
\item 
def {\bf parseaddr}
\begin{DoxyCompactList}\small\item\em Split email into Fullname and address. \end{DoxyCompactList}\item 
def {\bf parse\-\_\-addr}
\item 
def {\bf parse\-\_\-header}
\begin{DoxyCompactList}\small\item\em Decode headers gratuitously encoded to hide the content. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
string {\bfseries P\-A\-T\-\_\-\-I\-P4} = r'\textbackslash{}.'\label{namespaceMilter_1_1utils_ae4a17f563a8b9249dbbaa71cae1e53ba}

\item 
tuple {\bfseries ip4re} = re.\-compile(P\-A\-T\-\_\-\-I\-P4+'\$')\label{namespaceMilter_1_1utils_abd34cc3cac007cfef32c5a2b1a118fc7}

\item 
tuple {\bfseries ip6re}
\item 
int {\bfseries M\-A\-S\-K} = 0x\-F\-F\-F\-F\-F\-F\-F\-F\-L\label{namespaceMilter_1_1utils_a94942e91f59e9aa64e5a9b656eb81623}

\item 
int {\bfseries M\-A\-S\-K6} = 0x\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-F\-L\label{namespaceMilter_1_1utils_a79b183c5ad99eef23cefc546b28c5c06}

\end{DoxyCompactItemize}


\subsection{Detailed Description}
Miscellaneous functions. 

\subsection{Function Documentation}
\index{Milter\-::utils@{Milter\-::utils}!addr2bin@{addr2bin}}
\index{addr2bin@{addr2bin}!Milter::utils@{Milter\-::utils}}
\subsubsection[{addr2bin}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\-utils.\-addr2bin (
\begin{DoxyParamCaption}
\item[{}]{s}
\end{DoxyParamCaption}
)}\label{namespaceMilter_1_1utils_a36d06061159ad5a95127af72ffa82669}
\begin{DoxyVerb}Convert a string IPv4 address into an unsigned integer.\end{DoxyVerb}
 

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



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

\index{Milter\-::utils@{Milter\-::utils}!bin2long6@{bin2long6}}
\index{bin2long6@{bin2long6}!Milter::utils@{Milter\-::utils}}
\subsubsection[{bin2long6}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\-utils.\-bin2long6 (
\begin{DoxyParamCaption}
\item[{}]{s}
\end{DoxyParamCaption}
)}\label{namespaceMilter_1_1utils_af7e6c70a2ec53f9c257dd9931234ffcb}
\begin{DoxyVerb}Convert binary IP6 address into an unsigned Python long integer.\end{DoxyVerb}
 

Referenced by Milter.\-utils.\-addr2bin(), and Milter.\-utils.\-iniplist().

\index{Milter\-::utils@{Milter\-::utils}!iniplist@{iniplist}}
\index{iniplist@{iniplist}!Milter::utils@{Milter\-::utils}}
\subsubsection[{iniplist}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\-utils.\-iniplist (
\begin{DoxyParamCaption}
\item[{}]{ipaddr, }
\item[{}]{iplist}
\end{DoxyParamCaption}
)}\label{namespaceMilter_1_1utils_a805280d5df6da316bd11697985e1c40a}
\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('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().

\index{Milter\-::utils@{Milter\-::utils}!parse\-\_\-addr@{parse\-\_\-addr}}
\index{parse\-\_\-addr@{parse\-\_\-addr}!Milter::utils@{Milter\-::utils}}
\subsubsection[{parse\-\_\-addr}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\-utils.\-parse\-\_\-addr (
\begin{DoxyParamCaption}
\item[{}]{t}
\end{DoxyParamCaption}
)}\label{namespaceMilter_1_1utils_ade49f32a7a0e1a6f765eecf60527a9ba}
\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}}
\subsubsection[{parse\-\_\-header}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\-utils.\-parse\-\_\-header (
\begin{DoxyParamCaption}
\item[{}]{val}
\end{DoxyParamCaption}
)}\label{namespaceMilter_1_1utils_a8bdd90c627a4bdd198d277c58140c4bb}


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 \begin{DoxyVerb}Decode headers gratuitously encoded to hide the content.
\end{DoxyVerb}
 
\end{DoxyReturn}
\index{Milter\-::utils@{Milter\-::utils}!parseaddr@{parseaddr}}
\index{parseaddr@{parseaddr}!Milter::utils@{Milter\-::utils}}
\subsubsection[{parseaddr}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\-utils.\-parseaddr (
\begin{DoxyParamCaption}
\item[{}]{t}
\end{DoxyParamCaption}
)}\label{namespaceMilter_1_1utils_a2dd9985a11904eea0e3ede29dfc59bf0}


Split email into Fullname and address. 

This replaces {\ttfamily email.\-Utils.\-parseaddr} but fixes some {\tt tricky test cases}.\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', 'addr...@example.com')
>>> parseaddr('a(WRONG)@b')
('WRONG', 'a@b')
\end{DoxyVerb}
 

\subsection{Variable Documentation}
\index{Milter\-::utils@{Milter\-::utils}!ip6re@{ip6re}}
\index{ip6re@{ip6re}!Milter::utils@{Milter\-::utils}}
\subsubsection[{ip6re}]{\setlength{\rightskip}{0pt plus 5cm}tuple Milter.\-utils.\-ip6re}\label{namespaceMilter_1_1utils_a9dfca7f9906fdc8c66317bb148f9bdf0}
{\bfseries Initial value\-:}
\begin{DoxyCode}
1 = re.compile(                 \textcolor{stringliteral}{'(?:%(hex4)s:)\{6\}%(ls32)s$'}
2                    \textcolor{stringliteral}{'|::(?:%(hex4)s:)\{5\}%(ls32)s$'}
3                   \textcolor{stringliteral}{'|(?:%(hex4)s)?::(?:%(hex4)s:)\{4\}%(ls32)s$'}
4     \textcolor{stringliteral}{'|(?:(?:%(hex4)s:)\{0,1\}%(hex4)s)?::(?:%(hex4)s:)\{3\}%(ls32)s$'}
5     \textcolor{stringliteral}{'|(?:(?:%(hex4)s:)\{0,2\}%(hex4)s)?::(?:%(hex4)s:)\{2\}%(ls32)s$'}
6     \textcolor{stringliteral}{'|(?:(?:%(hex4)s:)\{0,3\}%(hex4)s)?::%(hex4)s:%(ls32)s$'}
7     \textcolor{stringliteral}{'|(?:(?:%(hex4)s:)\{0,4\}%(hex4)s)?::%(ls32)s$'}
8     \textcolor{stringliteral}{'|(?:(?:%(hex4)s:)\{0,5\}%(hex4)s)?::%(hex4)s$'}
9     \textcolor{stringliteral}{'|(?:(?:%(hex4)s:)\{0,6\}%(hex4)s)?::$'}
10   % \{
11     \textcolor{stringliteral}{'ls32'}: \textcolor{stringliteral}{r'(?:[0-9a-f]\{1,4\}:[0-9a-f]\{1,4\}|%s)'}%PAT\_IP4,
12     \textcolor{stringliteral}{'hex4'}: \textcolor{stringliteral}{r'[0-9a-f]\{1,4\}'}
13     \}, re.IGNORECASE)
\end{DoxyCode}
