YaWK  24.1
Yet another WebKit
webmail-setFlagged.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/db.php';
8 require_once '../../system/classes/settings.php';
9 require_once '../../system/classes/webmail.php';
10 // create db object
11 $db = new \YAWK\db();
12 // create webmail object
13 $webmail = new \YAWK\webmail();
14 
15 // let php know we need these classes:
16 use SSilence\ImapClient\ImapClientException;
17 use SSilence\ImapClient\ImapClient as Imap;
18 
19 // get all webmail setting values into an array
21 // mailbox server (imap.server.tld)
22 $server = $webmailSettings['webmail_imap_server'];
23 // mailbox user ([email protected])
24 $username = $webmailSettings['webmail_imap_username'];
25 // mailbox password
26 $password = $webmailSettings['webmail_imap_password'];
27 // encryption type (ssl, tsl, null)
28 $encryption = "/" . $webmailSettings['webmail_imap_encrypt'];
29 // port (default: 993)
30 $port = ":" . $webmailSettings['webmail_imap_port'];
31 // novalidate-cert
32 $novalidate = $webmailSettings['webmail_imap_novalidate'];
33 // create options array
35 
36 // lets go: open imap connection, check state and toggle required
37 try
38 { // open connection to imap server
39  $imap = new Imap($server.$port.$encryption, $username, $password, $encryption, 0, 0, $options);
40  // connection successful, error = false
41  $error = false;
42 
43  // @var $_POST['state'] string (seen|unseen) : check which state should be toggled
44  if (isset($_POST['state']))
45  { // if email should be toggled to state 'not flagged'
46  if ($_POST['state'] === "setUnFlagged")
47  { // remove flag from message
48  if ($webmail->removeFlags($imap->getImap(), $_POST['uid']) == true)
49  { // remove flag successful
50  echo "true";
51  }
52  else
53  { // remove flag failed
54  echo "false";
55  }
56  }
57  else
58  { // set message as flagged
59  if ($webmail->markAsFlagged($imap->getImap(), $_POST['uid']) == true)
60  { // set flag successful
61  echo "true";
62  }
63  else
64  { // set flag failed
65  echo "false";
66  }
67  }
68  }
69 }
70  // open imap connection failed...
71 catch (ImapClientException $error)
72 { // no errors in production...
73  echo "false";
74  echo "<script>console.log('.$error.');</script>";
75 }
76 ?>
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