$o .= $header;
- $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
- FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
- WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
- intval(local_user()),
- intval($a->argv[1])
+ $message = DBA::fetchFirst("
+ SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
+ FROM `mail`
+ LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
+ WHERE `mail`.`uid` = ? AND `mail`.`id` = ?
+ LIMIT 1",
+ local_user(),
+ $a->argv[1]
);
- if (DBA::isResult($r)) {
- $contact_id = $r[0]['contact-id'];
- $convid = $r[0]['convid'];
-
- $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", DBA::escape($r[0]['parent-uri']));
- if ($convid)
- $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ",
- DBA::escape($r[0]['parent-uri']),
- intval($convid)
- );
+ if (DBA::isResult($message)) {
+ $contact_id = $message['contact-id'];
- $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
- FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
- WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC",
- intval(local_user())
+ $params = [
+ local_user(),
+ $message['parent-uri']
+ ];
+
+ if ($message['convid']) {
+ $sql_extra = "AND (`mail`.`parent-uri` = ? OR `mail`.`convid` = ?)";
+ $params[] = $message['convid'];
+ } else {
+ $sql_extra = "AND `mail`.`parent-uri` = ?";
+ }
+ $messages_stmt = DBA::p("
+ SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
+ FROM `mail`
+ LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
+ WHERE `mail`.`uid` = ?
+ $sql_extra
+ ORDER BY `mail`.`created` ASC",
+ ...$params
);
+
+ $messages = DBA::toArray($messages_stmt);
+
+ DBA::update('mail', ['seen' => 1], ['parent-uri' => $message['parent-uri'], 'uid' => local_user()]);
} else {
$messages = false;
}
+
if (!DBA::isResult($messages)) {
notice(L10n::t('Message not available.') . EOL);
return $o;
}
- $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
- DBA::escape($r[0]['parent-uri']),
- intval(local_user())
- );
-
$tpl = Renderer::getMarkupTemplate('msg-header.tpl');
$a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
'$baseurl' => System::baseUrl(true),
$unknown = false;
foreach ($messages as $message) {
- if ($message['unknown'])
+ if ($message['unknown']) {
$unknown = true;
+ }
+
if ($message['from-url'] == $myprofile) {
$from_url = $myprofile;
$sparkle = '';
return false;
}
- q(
- "INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
- VALUES (%d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
- intval($importer["uid"]),
- DBA::escape($msg_guid),
- intval($conversation["id"]),
- DBA::escape($person["name"]),
- DBA::escape($person["photo"]),
- DBA::escape($person["url"]),
- intval($contact["id"]),
- DBA::escape($subject),
- DBA::escape($body),
- 0,
- 0,
- DBA::escape($message_uri),
- DBA::escape($author.":".$guid),
- DBA::escape($msg_created_at)
- );
+ DBA::insert('mail', [
+ 'uid' => $importer['uid'],
+ 'guid' => $msg_guid,
+ 'convid' => $conversation['id'],
+ 'from-name' => $person['name'],
+ 'from-photo' => $person['photo'],
+ 'from-url' => $person['url'],
+ 'contact-id' => $contact['id'],
+ 'title' => $subject,
+ 'body' => $body,
+ 'seen' => 0,
+ 'reply' => 0,
+ 'uri' => $message_uri,
+ 'parent-uri' => $author . ':' . $guid,
+ 'created' => $msg_created_at
+ ]);
DBA::unlock();
DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]);
- notification(
- [
+ notification([
"type" => NOTIFY_MAIL,
"notify_flags" => $importer["notify-flags"],
"language" => $importer["language"],
"source_link" => $person["url"],
"source_photo" => $person["photo"],
"verb" => ACTIVITY_POST,
- "otype" => "mail"]
- );
+ "otype" => "mail"
+ ]);
+
return true;
}
return false;
}
- q(
- "INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
- VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
- intval($importer["uid"]),
- DBA::escape($guid),
- intval($conversation["id"]),
- DBA::escape($person["name"]),
- DBA::escape($person["photo"]),
- DBA::escape($person["url"]),
- intval($contact["id"]),
- DBA::escape($conversation["subject"]),
- DBA::escape($body),
- 0,
- 1,
- DBA::escape($message_uri),
- DBA::escape($author.":".$conversation["guid"]),
- DBA::escape($created_at)
- );
+ DBA::insert('mail', [
+ 'uid' => $importer['uid'],
+ 'guid' => $guid,
+ 'convid' => $conversation['id'],
+ 'from-name' => $person['name'],
+ 'from-photo' => $person['photo'],
+ 'from-url' => $person['url'],
+ 'contact-id' => $contact['id'],
+ 'title' => $conversation['subject'],
+ 'body' => $body,
+ 'seen' => 0,
+ 'reply' => 1,
+ 'uri' => $message_uri,
+ 'parent-uri' => $author.":".$conversation['guid'],
+ 'created' => $created_at
+ ]);
DBA::unlock();