By eloiguell on
I don't know how to do a patch. I'm sorry.
I have customized simplenews.module to blocking forever unsubscribed emails for legal reasons.
It creates a blocked user with mail=$mail and name=$mai when unsubscribe a user only if doesn't exist user.
When subscribe email (via mass or via subscription in my newsletter) if blocked user with this email exists it doesn't subscribe it.
/**
* Subscribe a user to a newsletter or send a confirmation mail.
*
* The $confirm parameter determines the action:
* FALSE = The user is subscribed
* TRUE = User receives an email to verify the address and complete the subscription
* A new subscription account is created when the user is subscribed to the first newsletter
*
* @param string $mail
* The email address to subscribe to the newsletter.
* @param integer $tid
* The term ID of the newsletter.
* @param boolean $confirm
* TRUE = send confirmation mail; FALSE = subscribe immediate to the newsletter
* @param string $preferred_language
* The language code (i.e. 'en', 'nl') of the user preferred language.
* Use '' for the site default language.
* Use NULL for the language of the current page.
*/
function simplenews_subscribe_user($mail, $tid, $confirm = TRUE, $preferred_language = NULL) {
global $language;
//Prevent mismatches from accidental capitals in mail address
$mail = strtolower($mail);
// Get current subscriptions if any.
$account = (object) array('mail' => $mail);
$subscription = simplenews_get_subscription($account);
// If user is not subscribed to ANY newsletter, create a subscription account
if ($subscription->snid == 0) {
// To subscribe a user:
// - Fetch the users uid.
// - Determine the user preferred language.
// - Add the user to the database.
// - Get the full subscription object based on the mail address.
// Note that step 3 gets subscription data based on mail address because the uid can be 0 (for anonymous users)
$account = _simplenews_user_load($mail);
// If the site is multilingual:
// - Anonymous users are subscribed with their preferred language
// equal to the language of the current page.
// - Registered users will be subscribed with their default language as
// set in their account settings.
// By default the preferred language is not set.
if (variable_get('language_count', 1) > 1) {
if ($account->uid) {
$preferred_language = $account->language;
}
else {
$preferred_language = isset($preferred_language) ? $preferred_language : $language->language;
}
}
$existeix_user = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE mail = '$mail' AND status=0"));
if($existeix_user)
{
//si esta bloquejat no fa res
}else
{
db_query("INSERT INTO {simplenews_subscriptions} (mail, uid, language, activated) VALUES ('%s', %d, '%s', %d)", $mail, $account->uid, $preferred_language, 1);
$subscription = simplenews_get_subscription($account);
}
}
if ($confirm) {
// Send confirmation email to user to complete subscription or to tell
// them that he or she is already subscribed.
// Confirmation mail is in the user preferred language which is by default the language_default().
$params['from'] = _simplenews_set_from();
$params['context']['newsletter'] = taxonomy_get_term($tid);
$params['context']['account'] = $subscription;
drupal_mail('simplenews', 'subscribe', $mail, $subscription->language, $params, $params['from']['address']);
}
elseif (!isset($subscription->tids[$tid])) {
// OR add user to newsletter relationship if not already subscribed.
db_query("INSERT INTO {simplenews_snid_tid} (snid, tid) VALUES (%d, %d)", $subscription->snid, $tid);
// Execute simplenews subscribe trigger.
simplenews_call_actions('subscribe', $subscription);
}
return TRUE;
}
/**
* Unsubscribe a user from a newsletter or send a confirmation mail.
*
* The $confirm parameter determines the action:
* FALSE = The user is unsubscribed
* TRUE = User receives an email to verify the address and complete the unsubscription
* The subscription account is deleted when the user is unsubscribed to the last newsletter
*
* @param string $mail The email address to unsubscribe from the newsletter.
* @param integer $tid The term ID of the newsletter.
* @param boolean $confirm TRUE = send confirmation mail; FALSE = unsubscribe immediate from the newsletter
*/
function simplenews_unsubscribe_user($mail, $tid, $confirm = TRUE) {
//Prevent mismatches from accidental capitals in mail address
$mail = strtolower($mail);
$account = (object) array('mail' => $mail);
$subscription = simplenews_get_subscription($account);
// The unlikely case that a user is subscribed from a non existing newsletter is logged
if (!$newsletter = taxonomy_get_term($tid)) {
watchdog('simplenews', 'Attempt to unsubscribe from non existing newsletter term ID %id', array('%id' => $tid), WATCHDOG_ERROR);
return FALSE;
}
if ($confirm) {
// Send confirmation email to user to complete unsubscription
// or to tell them that he or she is not subscribed
// Confirmation mail is in the user preferred language.
$params['from'] = _simplenews_set_from();
$params['context']['newsletter'] = $newsletter;
$params['context']['account'] = $subscription;
drupal_mail('simplenews', 'unsubscribe', $mail, $subscription->language, $params, $params['from']['address']);
}
elseif (isset($subscription->tids[$tid])) {
// OR remove the user from the newsletter.
db_query('DELETE FROM {simplenews_snid_tid} WHERE snid = %d AND tid = %d', $subscription->snid, $tid);
// Clean up subscription account if user is not subscribed to any newsletter anymore
if (!db_result(db_query("SELECT COUNT(*) FROM {simplenews_snid_tid} t WHERE t.snid = %d", $subscription->snid))) {
db_query('DELETE FROM {simplenews_subscriptions} WHERE snid = %d', $subscription->snid);
}
// Execute simplenews unsubscribe trigger
simplenews_call_actions('unsubscribe', $subscription);
}
//en tots els casos inserim un usuari blockejat amb aquesta adreça per evitar subscripcions futures
$existeix_user = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE mail = '$mail'"));
if($existeix_user)
{
//db_query("UPDATE {users} SET status=0 WHERE mail = '$mail'" );
}else
{
db_query("INSERT INTO {users} ( name , mail , status ) VALUES ( '$mail', '$mail', 0)" );
}
return TRUE;
}
Comments
Great start
This is a great start! Simplenews has long needed an unsubscribe forever list. I am not super-attracted to blocking the member, however, as it may be a legitimate member who just does not want the newsletter.
Still, great start!
:)