Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
447399e8
Commit
447399e8
authored
Jun 21, 2014
by
Michael Kropat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update mail tool to pass api key auth
parent
067052d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
1 deletion
+17
-1
mail.py
tools/mail.py
+17
-1
No files found.
tools/mail.py
View file @
447399e8
...
@@ -3,7 +3,11 @@
...
@@ -3,7 +3,11 @@
import
sys
,
getpass
,
urllib
.
request
,
urllib
.
error
import
sys
,
getpass
,
urllib
.
request
,
urllib
.
error
def
mgmt
(
cmd
,
data
=
None
):
def
mgmt
(
cmd
,
data
=
None
):
req
=
urllib
.
request
.
Request
(
'http://localhost:10222'
+
cmd
,
urllib
.
parse
.
urlencode
(
data
)
.
encode
(
"utf8"
)
if
data
else
None
)
mgmt_uri
=
'http://localhost:10222'
setup_key_auth
(
mgmt_uri
)
req
=
urllib
.
request
.
Request
(
mgmt_uri
+
cmd
,
urllib
.
parse
.
urlencode
(
data
)
.
encode
(
"utf8"
)
if
data
else
None
)
try
:
try
:
response
=
urllib
.
request
.
urlopen
(
req
)
response
=
urllib
.
request
.
urlopen
(
req
)
except
urllib
.
error
.
HTTPError
as
e
:
except
urllib
.
error
.
HTTPError
as
e
:
...
@@ -20,6 +24,18 @@ def read_password():
...
@@ -20,6 +24,18 @@ def read_password():
second
=
getpass
.
getpass
(
' (again): '
)
second
=
getpass
.
getpass
(
' (again): '
)
return
first
return
first
def
setup_key_auth
(
mgmt_uri
):
key
=
open
(
'/var/lib/mailinabox/api.key'
)
.
read
()
.
strip
()
auth_handler
=
urllib
.
request
.
HTTPBasicAuthHandler
()
auth_handler
.
add_password
(
realm
=
'Mail-in-a-Box Management Server'
,
uri
=
mgmt_uri
,
user
=
key
,
passwd
=
''
)
opener
=
urllib
.
request
.
build_opener
(
auth_handler
)
urllib
.
request
.
install_opener
(
opener
)
if
len
(
sys
.
argv
)
<
2
:
if
len
(
sys
.
argv
)
<
2
:
print
(
"Usage: "
)
print
(
"Usage: "
)
print
(
" tools/mail.py user (lists users)"
)
print
(
" tools/mail.py user (lists users)"
)
...
...
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