10 define(
'MAILINGLIST_SUB_NO', 0);
11 define(
'MAILINGLIST_SUB_NOMAIL', 1);
12 define(
'MAILINGLIST_SUB_INDEX', 2);
13 define(
'MAILINGLIST_SUB_DIGEST', 5);
14 define(
'MAILINGLIST_SUB_MIME_DIGEST', 6);
15 define(
'MAILINGLIST_SUB_NORMAL', 10);
25 $permissions[
'administer mailinglist members'] = array(
26 'title' => t(
'Administer Mailinglist Membership'),
29 foreach ($lists as $index => $list) {
30 $permissions[
'mailinglist ' . $index .
' member details'] = array(
31 'title' => t($list->admin_title .
' Member Details'),
43 'mailinglist_members' => array(
44 'worker callback' =>
'mailinglist_members_callback',
56 $queue = DrupalQueue::get(
'mailinglist_members');
57 if($queue->numberOfItems() > 0) {
63 foreach ($lists as $index => $list) {
64 if (isset($list->operations[
'members']) && $list->operations[
'members']) {
65 $queue = DrupalQueue::get(
'mailinglist_members');
66 $queue->createItem($list->admin_name);
79 $rolename =
'Mailingling List Subscriber ' . $list->admin_name;
80 if (!user_role_load_by_name($rolename)) {
81 $role =
new stdClass();
82 $role->name = $rolename;
83 user_role_save($role);
87 foreach ($list_schema as $table_name => $schema) {
88 $ret = db_create_table($table_name, $schema);
89 if ($ret) dpm($ret, $table_name);
100 foreach ($list_schema as $table_name => $schema) {
101 $ret = db_drop_table($table_name);
116 $list_name = $list->admin_name;
117 $list_schema = array();
118 $list_schema[
'mailinglist_members_subscribers__' . $list_name] = array(
119 'description' =>
'Table for holding the list of subscribers for the list ' . $list_name,
125 'description' =>
'Primary Key for table',
130 'description' =>
'EMail address of subscription'
135 'description' =>
'Domain of subscription (for stats)'
139 'description' =>
'Type of subscription'
142 'description' =>
'Time of last update',
144 'default' =>
'0000-00-00 00:00:00',
147 'description' =>
'Time of last individual update',
149 'default' =>
'0000-00-00 00:00:00',
151 'moderated' => array(
153 'description' =>
'It the subcriber currently moderated',
160 'description' =>
'Misc. Options for Subscripton',
161 'object default' => array(
165 'primary key' => array(
'sid'),
166 'unique key' => array(
167 'email' => array(
'email'),
170 'domain' => array(
'domain'),
171 'last_update' => array(
'last_update'),
172 'last_update_ind' => array(
'last_update_ind'),
175 $list_schema[
'mailinglist_members_subscriptions__' . $list_name] = array(
176 'description' =>
'Table for holding info about all subscription/unusubscription events for list',
182 'description' =>
'Primary Key for table',
188 'description' =>
'sid from subscribers table for this subscription',
191 'subscribe' => array(
195 'description' =>
'1 if the first_seen time is the time of subscription',
200 'primary key' => array(
'sub_key'),
202 'first_seen' => array(
'first_seen'),
203 'last_seen' => array(
'last_seen'),
204 'first_unseen' => array(
'first_unseen'),
206 'foreign keys' => array(
208 'table' =>
'mailinglist_members_subscribers__' . $list_name,
209 'columns' => array(
'sid',
'sid'),
213 $list->
schema($list_schema,
'members');
228 $email = strtolower($email);
229 $list_name = $list->admin_name;
230 $table =
'mailinglist_members_subscribers__' . $list_name;
231 $transaction = db_transaction();
232 $result = db_select($table,
's')
234 -> condition(
's.email', $email,
'=')
237 if ($result === FALSE) {
238 $list->log(
'New Member: ' . $email);
239 $domain = substr($email, strpos($email,
'@') +1);
240 $fields = array(
'email' => $email,
'domain' => $domain);
241 $result[
'sid'] = db_insert($table) -> fields($fields) -> execute();
243 return (
int)$result[
'sid'];
247 $email = strtolower($email);
248 $list_name = $list->admin_name;
249 $table =
'mailinglist_members_subscribers__' . $list_name;
250 $transaction = db_transaction();
251 $result = db_select($table,
's')
253 -> condition(
's.email', $email,
'=')
256 if ($result == FALSE) {
257 $list->log(
'Update: Subscriber not present: ' . $email, $list->LOG_ERROR);
258 dpm($email,
'Subscriber Not Present');
261 $key = (int)$result[
'sid'];
263 foreach ($info as $field => $value) {
266 $newinfo[
'sub_type'] = $value;
269 $newinfo[
'moderated'] = $value ? 1 : 0;
272 case 'last_update_ind':
273 $newinfo[$field] = $value;
281 if (!isset($newinfo[
'options'])) {
282 if (empty($result[
'options'])) {
283 $newinfo[
'options'] = array();
285 $newinfo[
'options'] = unserialize($result[
'options']);
286 unset($newinfo[
'options'][
'Email']);
289 $newinfo[
'options'][$field] = $value;
293 if (isset($newinfo[
'options'])) {
294 $newinfo[
'options'] = serialize($newinfo[
'options']);
296 $res = db_update($table) -> fields($newinfo) -> condition(
'sid', $key) -> execute();
355 if ($time === FALSE) $time = time();
357 $list->log(
'Subscribe @time @email', $list::LOG_DEBUG,
358 array(
'@email' => $email,
'@time' => $time));
360 $list_name = $list->admin_name;
361 $table =
'mailinglist_members_subscriptions__' . $list_name;
366 if ($time === FALSE) $time = time();
368 $list->log(
'Unsubscribe @time @email', $list::LOG_DEBUG,
369 array(
'@email' => $email,
'@time' => $time));
371 $list_name = $list->admin_name;
372 $table =
'mailinglist_members_subscriptions__' . $list_name;
396 $level = $list::LOG_DEBUG;
397 if ($time === FALSE) $time = time();
400 $list_name = $list->admin_name;
401 $table =
'mailinglist_members_subscriptions__' . $list_name;
403 $transaction = db_transaction();
405 $sql =
"SELECT * FROM {" . $table .
"}
406 WHERE sid = :sid and (first_unseen IS NULL or first_unseen = '0000-00-00 00:00:00' or :time <= first_unseen)
407 ORDER BY first_seen ASC LIMIT 1";
408 $result = db_query($sql, array(
':sid' => $sid,
':time' => $time)) -> fetchAssoc();
409 if ($result === FALSE) {
411 $list->log(
'Newly Seen: ' . $email);
414 'first_seen' => $time,
416 'last_seen' => $time,
417 'first_unseen' => null,
419 $level = $list::LOG_NOTICE;
420 $result[
'sub_key'] = db_insert($table) ->fields($result) -> execute();
422 $key = (int) $result[
'sub_key'];
423 if ($result[
'first_seen'] > $time) {
425 if ($result[
'subscribe'] > 0) {
427 $ts = strtotime($result[
'first_seen'])-1;
430 'first_seen' => $time,
432 'last_seen' => $time,
435 $level = $list::NOTICE;
436 $result[
'sub_key'] = db_insert($table) ->fields($result) -> execute();
441 'first_seen' => $time,
443 db_update($table) -> fields($info) -> condition(
'sub_key', $key) -> execute();
445 }
else if ($result[
'last_seen'] < $time) {
448 'last_seen' => $time,
450 $result = db_update($table) -> fields($info) ->
451 condition(
'sub_key', $key,
'=') -> execute();
454 $list->log(
'Seen @time @email', $level,
455 array(
'@email' => $email,
'@time' => $time));
475 if ($time === FALSE) $time = time();
477 $level = $list::LOG_DEBUG;
479 $list_name = $list->admin_name;
480 $table =
'mailinglist_members_subscriptions__' . $list_name;
481 $transaction = db_transaction();
482 $sql =
"SELECT * FROM {" . $table .
"}
483 WHERE sid = :sid and first_seen <= :time
484 ORDER BY first_seen DESC LIMIT 1";
485 $result = db_query($sql, array(
':sid' => $sid,
':time' => $time)) -> fetchAssoc();
487 if ($result == FALSE) {
488 $list->log(
'Unseen too Early $time @email', $list::LOG_ERROR, array(
'@email' => $email,
'@time' => $time));
490 $key = (int) $result[
'sub_key'];
491 if ($time < $result[
'last_seen']) {
494 'first_seen' => $result[
'last_seen'],
496 'last_seen' => $result[
'first_seen'],
497 'first_unseen' => $result[
'first_unseen'],
500 db_insert($table) ->fields($info) -> execute();
503 'last_seen' => $result[
'first_seen'],
504 'first_unseen' => $time,
507 $level = $list::LOG_NOTICE;
508 $result = db_update($table) -> fields($info) ->
509 condition(
'sub_key', $key,
'=') -> execute();
510 }
else if ($result[
'first_unseen'] == null || $time < $result[
'first_unseen']) {
512 'first_unseen' => $time,
514 $level = $list::LOG_NOTICE;
515 $result = db_update($table) -> fields($info) ->
516 condition(
'sub_key', $key,
'=') -> execute();
519 $list->log(
'Unseen @time @email', $level,
520 array(
'@email' => $email,
'@time' => $time));
524 $table =
'mailinglist_members_subscribers__' . $list_name;
528 db_update($table) -> fields($info) -> condition(
'sid', $sid) -> execute();
547 $data = $list->getMemberPage($page);
548 foreach ($data[
'members'] as $email => $info) {
550 if(substr($email, 0, 7) ==
'mailto:')
continue;
551 if(substr($email, -1) ==
'.')
continue;
556 return $data[
'next'];
573 if(!isset($list->parameters[
'ScanNext'])) {
574 $list->parameters[
'ScanNext'] = FALSE;
577 $next = $list->parameters[
'ScanNext'];
581 if(!isset($list->parameters[
'ScanStart'])) {
583 $list->parameters[
'ScanStart'] =
'0000';
586 $sql =
'SELECT * from {mailinglist_members_subscribers__' . $list->admin_name .
'}
587 WHERE last_update < :time AND sub_type > 0 LIMIT 1';
588 $result = db_query($sql, array(
':time' => $list->parameters[
'ScanStart']));
590 while($row = $result -> fetchAssoc()) {
593 $email = $row[
'email'];
594 $list->log(
'Scan Needs Update @time @email', $list::LOG_NOTICE, array(
'@email' => $email,
'@time' => $row[
'last_update']));
604 if($next === FALSE) {
606 $list->log(
'Member Scan Start',$list::LOG_NOTICE);
610 if($next === FALSE) {
618 $sql =
'SELECT * from {mailinglist_members_subscribers__' . $list->admin_name .
'}
619 WHERE sub_type > 0 ORDER BY last_update_ind ASC, last_update ASC LIMIT 1';
620 $result = db_query($sql, array(
':time' => $list->parameters[
'ScanStart']));
621 while($row = $result -> fetchAssoc()) {
622 $email = $row[
'email'];
623 $list->log(
'Individual Update @time @email', $list::LOG_DEBUG,
624 array(
'@email' => $email,
'@time' => $row[
'last_update_ind']));
628 $list->parameters[
'ScanNext'] = $next;
629 $list->log(
'Next: ' . serialize($next), $list::LOG_DEBUG);
630 ctools_export_crud_save($list->table, $list);
632 return $next !== FALSE;
646 $queue = DrupalQueue::get(
'mailinglist_members');
647 $queue->createItem($listname);
649 $list->log(
'Scan End', $list::LOG_INFO);
661 $info = $list->getMemberInfo($email);
676 if ($msg->header(
'XX-Archive')) {
697 return 'plugins/' . $owner .
'/' . $plugin_type;
_mailinglist_members_lookup($list, $email)
_mailinglist_members_lookup().
mailinglist_members_unseen($list, $email, $time=FALSE)
Mark a member as haven been not seen (ie wasn't subscribed) at a point in time.
_mailinglist_members_list_schema(MailinglistListInterface $list)
Builds the schema needed by mailinglist_members for a specific list.
mailinglist_members_update($list, $email, $info)
Interface to a mailing list.
mailinglist_members_update_ind($list, $email, $info)
mailinglist_members_cron_queue_info()
Implements hook_cron_queue_info().
const MAILINGLIST_SUB_NO
Defines for sub_types (subscription types)
mailinglist_list_load($list)
Load a list definition.
mailinglist_members_mailinglist_message($msg, $list)
Implements hook_mailinglist_message().
mailinglist_members_process_memberpage($list, $page)
Process one member page from the list.
mailinglist_members_memberid($list, $email)
Get sid for email address.
_mailinglist_datetime_schema($desc)
Return the schema for a 'datetime' field.
mailinglist_members_mailinglist_list_created($list)
Implements hook_mailinglist_list_created().
mailinglist_members_unsubscribe($list, $email, $time=FALSE)
mailinglist_members_cron()
Implements hook_cron().
mailinglist_email_name($email, $name, $count=0)
Lookup Email <-> Name combination.
mailinglist_members_subscribe($list, $email, $time=FALSE)
Subscription tracking routines.
mailinglist_members_ctools_plugin_directory($owner, $plugin_type)
Implements hook_ctools_plugin_directory().
mailinglist_members_mailinglist_list_delete($list)
Implements hook_mailinglist_list_delete().
mailinglist_members_seen($list, $email, $time=FALSE)
Mark a member as having been seen.
mailinglist_members_permission()
Implements hook_permission().
mailinglist_members_scan($list)
Process a partial scan of members for a mailinglist.
mailinglist_list_load_all($show_disabled=TRUE)
Load all mailinglists.
schema(&$schema, $type)
schema();
mailinglist_members_callback($listname)
_mailinglist_datetime_format($ts)
Convert a 'timestamp to a 'datetime'.