Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
python-munnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
python-munnel
Commits
2665e011
Commit
2665e011
authored
Feb 20, 2017
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial import.
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
0 deletions
+151
-0
README.rst
README.rst
+8
-0
munnel/__init__.py
munnel/__init__.py
+95
-0
setup.py
setup.py
+48
-0
No files found.
README.rst
0 → 100644
View file @
2665e011
Milter replacing RCTP TO addresses with configured ones
Intended to muzzle a mail-sending application while only touching its mail
relay.
"munnel" is a portmanteau, like milter: milter is a Mail fILTER, munnel is a
Mail fUNNEL. And it is a funnel, because wherever the mail tries to fall, it
will slide where configurations tells it to.
munnel/__init__.py
0 → 100644
View file @
2665e011
# This file is part of python-munnel
# Copyright (C) 2017 Nexedi
# Author: Vincent Pelletier <vincent@nexedi.com>
#
# python-munnel is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# python-functionfs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with python-munnel. If not, see <http://www.gnu.org/licenses/>.
import
argparse
import
libmilter
import
signal
import
sys
# XXX: this code is overcomplex because instance life scope is neither clearly
# documented nor clearly readable from the code. So give this code more chances
# to fail, to avoid letting mails go through unmodified.
class
Munnel
(
libmilter
.
ThreadMixin
,
libmilter
.
MilterProtocol
):
replacement_recipient_list
=
None
# Override in subclasses
existing_recipient_list
=
None
# Will be filled/reset during instance life
def
__init__
(
self
,
*
args
,
**
kw
):
libmilter
.
ThreadMixin
.
__init__
(
self
)
libmilter
.
MilterProtocol
.
__init__
(
self
,
*
args
,
**
kw
)
@
libmilter
.
noReply
def
mailFrom
(
self
,
frAddr
,
cmdDict
):
new_recipient_list
=
[]
set_recipient_list
=
self
.
__dict__
.
setdefault
(
'existing_recipient_list'
,
new_recipient_list
,
)
assert
new_recipient_list
is
set_recipient_list
@
libmilter
.
noReply
def
rcpt
(
self
,
recip
,
cmdDict
):
self
.
existing_recipient_list
.
append
(
recip
)
def
eob
(
self
,
cmdDict
):
delRcpt
=
self
.
delRcpt
for
recipient
in
self
.
__dict__
.
pop
(
'existing_recipient_list'
):
delRcpt
(
recipient
)
addRcpt
=
self
.
addRcpt
for
recipient
in
self
.
replacement_recipient_list
:
addRcpt
(
recipient
)
return
libmilter
.
CONTINUE
def
close
(
self
):
self
.
__dict__
.
pop
(
'existing_recipient_list'
,
None
)
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Milter replacing RCTP TO addresses with configured ones'
,
)
parser
.
add_argument
(
'--listen'
,
required
=
True
,
help
=
'Socket to listen to (format: "inet:$IP:$PORT" for network '
'socket, a bare path for unix socket)'
,
)
parser
.
add_argument
(
'recipient'
,
nargs
=
'+'
,
help
=
'Addresses to actually send mails to'
,
)
args
=
parser
.
parse_args
()
milter
=
libmilter
.
ThreadFactory
(
sockstr
=
args
.
listen
,
protocol
=
type
(
'ThisMunnel'
,
(
Munnel
,
),
{
'replacement_recipient_list'
:
args
.
recipient
,
},
),
opts
=
libmilter
.
SMFIF_DELRCPT
|
libmilter
.
SMFIF_ADDRCPT
,
sockChmod
=
0660
,
# Why is libmilter trying to chmod at all !?
)
try
:
milter
.
run
()
except
(
SystemExit
,
KeyboardInterrupt
):
pass
finally
:
milter
.
close
()
if
__name__
==
'__main__'
:
main
()
setup.py
0 → 100644
View file @
2665e011
# This file is part of python-munnel
# Copyright (C) 2017 Nexedi
# Author: Vincent Pelletier <vincent@nexedi.com>
#
# python-munnel is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# python-functionfs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with python-munnel. If not, see <http://www.gnu.org/licenses/>.
from
setuptools
import
setup
from
codecs
import
open
import
os
long_description
=
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'README.rst'
),
encoding
=
'utf8'
,
).
read
()
setup
(
name
=
'munnel'
,
description
=
next
(
x
for
x
in
long_description
.
splitlines
()
if
x
.
strip
()),
long_description
=
'.. contents::
\
n
\
n
'
+
long_description
,
keywords
=
'smtp milter funnel'
,
version
=
'0.1'
,
author
=
'Nexedi'
,
author_email
=
'vincent@nexedi.com'
,
url
=
'http://lab.nexedi.com/vpelletier/python-munnel'
,
# TODO: relocate to /nexedi
license
=
'GPLv3'
,
platforms
=
[
'any'
],
install_requires
=
[
'python-libmilter'
],
packages
=
[
'munnel'
],
classifiers
=
[
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)'
,
'Operating System :: OS Independent'
,
],
entry_points
=
{
'console_scripts'
:
[
'funnel=funnel:main'
,
],
}
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment