Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mwclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WebU
shared
mwclient
Commits
e9572e1c
Commit
e9572e1c
authored
10 years ago
by
Dan Michael O. Heggø
Browse files
Options
Downloads
Patches
Plain Diff
Update email method to use API
parent
083394be
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mwclient/client.py
+33
-17
33 additions, 17 deletions
mwclient/client.py
with
33 additions
and
17 deletions
mwclient/client.py
+
33
−
17
View file @
e9572e1c
...
@@ -310,23 +310,39 @@ class Site(object):
...
@@ -310,23 +310,39 @@ class Site(object):
# Actions
# Actions
def
email
(
self
,
user
,
text
,
subject
,
cc
=
False
):
def
email
(
self
,
user
,
text
,
subject
,
cc
=
False
):
"""
Sends email to a specified user on the wiki.
"""
"""
# TODO: Use api!
Send email to a specified user on the wiki.
postdata
=
{}
postdata
[
'
wpSubject
'
]
=
subject
>>>
try
:
postdata
[
'
wpText
'
]
=
text
...
site
.
email
(
'
SomeUser
'
,
'
Some message
'
,
'
Some subject
'
)
if
cc
:
...
except
mwclient
.
errors
.
NoSpecifiedEmailError
,
e
:
postdata
[
'
wpCCMe
'
]
=
'
1
'
...
print
'
The user does not accept email, or has not specified an email address.
'
postdata
[
'
wpEditToken
'
]
=
self
.
tokens
[
'
edit
'
]
postdata
[
'
uselang
'
]
=
'
en
'
Args:
postdata
[
'
title
'
]
=
u
'
Special:Emailuser/
'
+
user
user (str): User name of the recipient
text (str): Body of the email
data
=
self
.
raw_index
(
'
submit
'
,
**
postdata
)
subject (str): Subject of the email
if
'
var wgAction =
"
success
"
;
'
not
in
data
:
cc (bool): True to send a copy of the email to yourself (default is False)
if
'
This user has not specified a valid e-mail address
'
in
data
:
# Dirty hack
Returns:
raise
errors
.
NoSpecifiedEmailError
,
user
Dictionary of the JSON response
raise
errors
.
EmailError
,
data
Raises:
NoSpecifiedEmailError (mwclient.errors.NoSpecifiedEmailError): if recipient does not accept email
EmailError (mwclient.errors.EmailError): on other errors
"""
token
=
self
.
get_token
(
'
email
'
)
try
:
info
=
self
.
api
(
'
emailuser
'
,
target
=
user
,
subject
=
subject
,
text
=
text
,
ccme
=
cc
,
token
=
token
)
except
errors
.
APIError
,
e
:
if
e
[
0
]
==
u
'
noemail
'
:
raise
errors
.
NoSpecifiedEmail
(
user
,
e
[
1
])
raise
errors
.
EmailError
(
*
e
)
return
info
def
login
(
self
,
username
=
None
,
password
=
None
,
cookies
=
None
,
domain
=
None
):
def
login
(
self
,
username
=
None
,
password
=
None
,
cookies
=
None
,
domain
=
None
):
"""
Login to the wiki.
"""
"""
Login to the wiki.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment