Skip to content

Instantly share code, notes, and snippets.

@lucasaba
Last active February 10, 2020 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasaba/e2289aa8b423f2adf448562557ff5709 to your computer and use it in GitHub Desktop.
Save lucasaba/e2289aa8b423f2adf448562557ff5709 to your computer and use it in GitHub Desktop.
<?php
/**
* @param Mailbox $mailbox
* @return PecServer
*/
private function getServer(Mailbox $mailbox)
{
$server = new PecServer($mailbox->getHost(), $mailbox->getPort());
$server->setAuthentication($mailbox->getUsername(), $mailbox->getPassword());
return $server;
}
private function spostaMessaggioInCartella($msg_uid, $nomeCartella, Mailbox $mailbox)
{
$nomeCartellaInCuiSpostare = $mailbox->getMailbox().".$nomeCartella";
try {
$server = $this->getServer($mailbox);
if (! $server->hasMailBox($nomeCartellaInCuiSpostare)) {
$server->createMailBox($nomeCartellaInCuiSpostare);
}
$inboxMsg = $server->getMessageByUid($msg_uid);
if ($inboxMsg === false || $inboxMsg->moveToMailBox($nomeCartellaInCuiSpostare) === false) {
return false;
}
} catch (\RuntimeException $runtimeException) {
return null;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment