- $me = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
- intval($_SESSION['uid'])
- );
- $contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval($recipient),
- intval($_SESSION['uid'])
- );
-
- if(! (count($me) && (count($contact)))) {
- notice( t('Unable to locate contact information.') . EOL );
- return;
- }
-
- $hash = random_string();
- $uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . $_SESSION['uid'] . ':' . $hash ;
-
- if(! strlen($replyto))
- $replyto = $uri;
-
- $r = q("INSERT INTO `mail` ( `uid`, `from-name`, `from-photo`, `from-url`,
- `contact-id`, `title`, `body`, `delivered`, `seen`, `replied`, `uri`, `parent-uri`, `created`)
- VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s' )",
- intval($_SESSION['uid']),
- dbesc($me[0]['name']),
- dbesc($me[0]['thumb']),
- dbesc($me[0]['url']),
- intval($recipient),
- dbesc($subject),
- dbesc($body),
- 0,
- 0,
- 0,
- dbesc($uri),
- dbesc($replyto),
- datetime_convert()
- );
- $r = q("SELECT * FROM `mail` WHERE `uri` = '%s' and `uid` = %d LIMIT 1",
- dbesc($uri),
- intval($_SESSION['uid'])
- );
- if(count($r))
- $post_id = $r[0]['id'];
-
- $url = $a->get_baseurl();
-
- if($post_id) {
- proc_close(proc_open("php include/notifier.php \"$url\" \"mail\" \"$post_id\" > mail.log &",
- array(),$foo));
- notice( t('Message sent.') . EOL );
- }
- else {
- notice( t('Message could not be sent.') . EOL );
+
+ $ret = send_message($recipient, $body, $subject, $replyto);
+
+ switch($ret){
+ case -1:
+ notice( t('No recipient selected.') . EOL );
+ break;
+ case -2:
+ notice( t('Unable to locate contact information.') . EOL );
+ break;
+ case -3:
+ notice( t('Message could not be sent.') . EOL );
+ default:
+ info( t('Message sent.') . EOL );