Last active
November 28, 2019 10:59
-
-
Save codingdotlog/ccfca37c59b56b39b0759dc10e7a98ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Webklex\IMAP\Client; | |
use App\InsertTicket; | |
class EmailPollingService extends Controller { | |
public function check() { | |
$oClient = new Client([ | |
'host' => env("IMAP_HOST", "somedefaultvalue"), | |
'port' => env("IMAP_PORT", "somedefaultvalue"), | |
'encryption' => env("IMAP_ENCRYPTION", "somedefaultvalue"), | |
'validate_cert' => env("IMAP_VALIDATE_CERT", "somedefaultvalue"), | |
'username' => env("IMAP_USERNAME", "somedefaultvalue"), | |
'password' => env("IMAP_PASSWORD", "somedefaultvalue"), | |
'protocol' => env("IMAP_PROTOCOL", "somedefaultvalue"), | |
]); | |
$oClient->connect(); | |
$aFolder = $oClient->getFolders(); | |
foreach($aFolder as $oFolder){ | |
$aMessage = $oFolder->query()->since(now()->subDays(1))->get(); | |
foreach($aMessage as $oMessage) { | |
/* | |
InsertTicket::create([ | |
'subject'=>$oMessage->getSubject(), | |
'body'=>$oMessage->getSubject(), | |
['body' => $oMessage->getHTMLBody(true)], | |
]); | |
*/ | |
$ticket = InsertTicket::firstOrNew( | |
['subject' => $oMessage->getSubject()], | |
['body' => $oMessage->getHTMLBody(true)], | |
['sender' => $oMessage->getSender()[0]->mail], | |
['opened_at' => $oMessage->getDate()], | |
['attachment' => $oMessage->getAttachments()->count()]); | |
$ticket->save(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class InsertTicket extends Model | |
{ | |
protected $table = 'tickets'; | |
protected $fillable = ['subject', 'body', 'sender', 'opened_at', 'attachment']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment