- if (get_pconfig($item['uid'], 'mailstream', 'enabled') === 'on') {
- if ($item['uid'] && $item['contact-id'] && $item['uri']) {
- q("INSERT INTO `mailstream_item` (`uid`, `contact-id`, `uri`, `message-id`) " .
- "VALUES (%d, '%s', '%s', '%s')", intval($item['uid']),
- intval($item['contact-id']), dbesc($item['uri']), dbesc(mailstream_generate_id($a, $item['uri'])));
- $r = q('SELECT * FROM `mailstream_item` WHERE `uid` = %d AND `contact-id` = %d AND `uri` = "%s"', intval($item['uid']), intval($item['contact-id']), dbesc($item['uri']));
- if (count($r) != 1) {
- logger('mailstream_post_remote_hook: Unexpected number of items returned from mailstream_item', LOGGER_ERROR);
- return;
- }
- $ms_item = $r[0];
- logger('mailstream_post_remote_hook: created mailstream_item '
- . $ms_item['id'] . ' for item ' . $item['uri'] . ' '
- . $item['uid'] . ' ' . $item['contact-id'], LOGGER_DATA);
- $r = q('SELECT * FROM `user` WHERE `uid` = %d', intval($item['uid']));
- if (count($r) != 1) {
- logger('mailstream_post_remote_hook: Unexpected number of users returned', LOGGER_ERROR);
- return;
- }
- $user = $r[0];
- mailstream_send($a, $ms_item, $item, $user);
- }
+ if (!get_pconfig($item['uid'], 'mailstream', 'enabled')) {
+ return;
+ }
+ if (!$item['uid']) {
+ return;
+ }
+ if (!$item['contact-id']) {
+ return;
+ }
+ if (!$item['uri']) {
+ return;
+ }
+
+ q("INSERT INTO `mailstream_item` (`uid`, `contact-id`, `uri`, `message-id`) " .
+ "VALUES (%d, '%s', '%s', '%s')", intval($item['uid']),
+ intval($item['contact-id']), dbesc($item['uri']), dbesc(mailstream_generate_id($a, $item['uri'])));
+ $r = q('SELECT * FROM `mailstream_item` WHERE `uid` = %d AND `contact-id` = %d AND `uri` = "%s"', intval($item['uid']), intval($item['contact-id']), dbesc($item['uri']));
+ if (count($r) != 1) {
+ logger('mailstream_post_remote_hook: Unexpected number of items returned from mailstream_item', LOGGER_NORMAL);
+ return;
+ }
+ $ms_item = $r[0];
+ logger('mailstream_post_remote_hook: created mailstream_item '
+ . $ms_item['id'] . ' for item ' . $item['uri'] . ' '
+ . $item['uid'] . ' ' . $item['contact-id'], LOGGER_DATA);
+ $user = mailstream_get_user($item['uid']);
+ if (!$user) {
+ logger('mailstream_post_remote_hook: no user ' . $item['uid'], LOGGER_NORMAL);
+ return;