Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
6f973303
Commit
6f973303
authored
Nov 18, 2009
by
Andrew Robert Nicols
Committed by
Richard Mansfield
Nov 20, 2009
Browse files
Check to see whether a user has disabled email
Signed-off-by:
Andrew Robert Nicols
<
andrew.nicols@luns.net.uk
>
parent
4d74c0b0
Changes
2
Show whitespace changes
Inline
Side-by-side
htdocs/lib/errors.php
View file @
6f973303
...
...
@@ -790,6 +790,11 @@ class CryptException extends SystemException {}
*/
class
EmailException
extends
SystemException
{}
/**
* Exception - Email is disabled for this user
*/
class
EmailDisabledException
extends
EmailException
{}
/**
* Exception - artefact not found
*/
...
...
htdocs/lib/user.php
View file @
6f973303
...
...
@@ -201,6 +201,7 @@ function expected_account_preferences() {
'messages'
=>
'allow'
,
'lang'
=>
'default'
,
'addremovecolumns'
=>
0
,
'maildisabled'
=>
0
,
'tagssideblockmaxtags'
=>
get_config
(
'tagssideblockmaxtags'
),
);
}
...
...
@@ -267,6 +268,7 @@ function get_profile_field($userid, $field) {
* @param string $messagehtml html version of email (will send both html and text)
* @param array $customheaders email headers
* @throws EmailException
* @throws EmailDisabledException
*/
function
email_user
(
$userto
,
$userfrom
,
$subject
,
$messagetext
,
$messagehtml
=
''
,
$customheaders
=
null
)
{
global
$IDPJUMPURL
;
...
...
@@ -282,6 +284,10 @@ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='',
throw
new
InvalidArgumentException
(
"empty user given to email_user"
);
}
if
(
!
$mailinfo
=
can_receive_email
(
$userto
))
{
throw
new
EmailDisabledException
(
"email for this user has been disabled"
);
}
// If the user is a remote xmlrpc user, trawl through the email text for URLs
// to our wwwroot and modify the url to direct the user's browser to login at
// their home site before hitting the link on this site
...
...
@@ -405,6 +411,37 @@ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='',
.
"Error from phpmailer was: "
.
$mail
->
ErrorInfo
);
}
/**
* Checks whether an email address is allowed to be sent email
* This checks whether that user has email turned on, and if so whether
* that user has hit their email bounce threshold.
*
* @param object $userto the user to check bounce threshold for
* @return mixed Returns false if the user cannot send an email or an
* object containing the email properties if they can
*/
function
can_receive_email
(
$userto
)
{
if
(
!
$userto
->
id
)
{
// No user ID was provided by email_user
return
new
StdClass
;
}
// Retrieve data for this mail address
if
(
!
$mailinfo
=
get_record_select
(
'artefact_internal_profile_email'
,
'owner = ? AND email = ?'
,
array
(
$userto
->
id
,
$userto
->
email
)))
{
// Since we don't know who this address belongs to, we must return
// an object. They're not disabled, we just don't know about them.
return
new
StdClass
;
}
// If this user has email disabled, then return false.
if
(
get_account_preference
(
$mailinfo
->
owner
,
'maildisabled'
)
==
1
)
{
// Email is disabled for this user
return
false
;
}
return
$mailinfo
;
}
/**
* Update the send count for the specified e-mail address
*
...
...
Write
Preview
Supports
Markdown
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