YaWK  24.1
Yet another WebKit
webmail-markAsSeen.php
Go to the documentation of this file.
1 <?php
2 // include required imap classes
3 require_once "../../system/engines/imapClient/ImapClient.php";
4 require_once "../../system/engines/imapClient/ImapClientException.php";
5 require_once "../../system/engines/imapClient/ImapConnect.php";
6 // include required yawk classes
7 require_once '../../system/classes/settings.php';
8 require_once '../../system/classes/db.php';
9 // create db object
10 $db = new \YAWK\db();
11 
12 // let php know we need these classes:
13 use SSilence\ImapClient\ImapClientException;
14 use SSilence\ImapClient\ImapClient as Imap;
15 
16 // get all webmail setting values into an array
18 // mailbox server (imap.server.tld)
19 $server = $webmailSettings['webmail_imap_server'];
20 // mailbox user ([email protected])
21 $username = $webmailSettings['webmail_imap_username'];
22 // mailbox password
23 $password = $webmailSettings['webmail_imap_password'];
24 // encryption type (ssl, tsl, null)
25 $encryption = "/" . $webmailSettings['webmail_imap_encrypt'];
26 // port (default: 993)
27 $port = ":" . $webmailSettings['webmail_imap_port'];
28 // novalidate-cert
29 $novalidate = $webmailSettings['webmail_imap_novalidate'];
30 // create options array
32 
33 // lets go: open imap connection, check state and toggle required
34 try
35 { // open connection to imap server
36  $imap = new Imap($server.$port.$encryption, $username, $password, $encryption, 0, 0, $options);
37  // connection successful, error = false
38  $error = false;
39 
40  // @var $_POST['state'] string (seen|unseen) : check which state should be toggled
41  if (isset($_POST['state']))
42  { // if email should be toggled to state unseen
43  if ($_POST['state'] === "setUnseen")
44  { // flag message as UNSEEN
45  if ($imap->setUnseenMessage($_POST['msgno']) == true)
46  { // set unseen successful
47  echo "true";
48  }
49  else
50  { // set unseen failed
51  echo "false";
52  }
53  }
54  else
55  { // flag message as SEEN
56  if ($imap->setSeenMessage($_POST['msgno']) == true)
57  { // set seen successful
58  echo "true";
59  }
60  else
61  { // set seen failed
62  echo "false";
63  }
64  }
65  }
66 }
67  // open imap connection failed...
68 catch (ImapClientException $error)
69 { // no errors in production...
70  echo "false";
71  echo "<script>console.log('.$error.');</script>";
72 }
73 ?>
static getValueSettingsArray($db, $property)
Returns an array containing property as key and values corresponding to this property where p like $p...
Definition: settings.php:41
$webmailSettings