function __construct(CuentaRepository $cuentaRepo, UsuarioRepository $usuarioRepo)
 {
     $this->middleware('auth');
     $this->cuentaRepository = $cuentaRepo;
     $this->usuarioRepository = $usuarioRepo;
     if (!$this->usuarioRepository->hasCuenta(Auth::user()->id)) {
         throw new Exception("El usuario no tiene Cuentas Asignadas");
     }
     $id = $this->usuarioRepository->find(Auth::user()->id)->Cuenta->id;
     $this->cuenta = $this->cuentaRepository->obtenercuenta($id, 'zimbra');
     $hostname = "sanclemente.cl";
     $port = "993";
     $flags = "ssl/novalidate-cert";
     $username = $this->cuenta->id_zimbra;
     $password = $this->cuenta->pass_zimbra;
     $this->carpeta = 'attachments/' . $username;
     if (!File::exists('attachments')) {
         File::makeDirectory('attachments');
     }
     if (!File::exists($this->carpeta)) {
         //Crear carpeta de archivos adjuntos
         File::makeDirectory($this->carpeta);
     }
     if (File::lastModified($this->carpeta) < time() - 24 * 60 * 60) {
         //Si los archivos llevan mas de un dia
         File::cleanDirectory($this->carpeta);
         //Se eliminan los archivos adjuntos del servidor intranet
     }
     $Server = new Server($hostname, $port, $flags);
     $search = new SearchExpression();
     $search->addCondition(new Unseen('UNSEEN'));
     $this->connection = $Server->authenticate($username, $password);
     $this->unseen = $this->connection->getMailbox('INBOX')->getMessages($search)->count();
 }
 public function validateCredentials(Authenticatable $user, array $credentials)
 {
     $server = new Server($this->config["server"]);
     try {
         $connection = $server->authenticate($credentials["email"], $credentials["password"]);
     } catch (AuthenticationFailedException $e) {
         return false;
     }
     return true;
 }
예제 #3
0
 public static function setUpBeforeClass()
 {
     $server = new Server('imap.gmail.com');
     if (false === \getenv('EMAIL_USERNAME')) {
         throw new \RuntimeException('Please set environment variable EMAIL_USERNAME before running functional tests');
     }
     if (false === \getenv('EMAIL_PASSWORD')) {
         throw new \RuntimeException('Please set environment variable EMAIL_PASSWORD before running functional tests');
     }
     static::$connection = $server->authenticate(\getenv('EMAIL_USERNAME'), \getenv('EMAIL_PASSWORD'));
 }
예제 #4
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $username = $request->user()->email;
     $password = $request->user()->clear;
     $server = new Server(env("IMAP_SERVER", "localhost"));
     $connection = $server->authenticate($username, $password);
     $mailboxes = $connection->getMailboxes();
     $mb_array = [];
     if (!empty($mailboxes)) {
         foreach ($mailboxes as $mailbox) {
             $name = $mailbox->getName();
             $name = str_replace(".", "/", $name);
             $mb_array[] = $name;
         }
     }
     sort($mb_array);
     return response()->json($mb_array);
 }
예제 #5
0
 /**
  * @expectedException \Ddeboer\Imap\Exception\AuthenticationFailedException
  */
 public function testFailedAuthenticate()
 {
     $server = new Server('imap.gmail.com');
     $server->authenticate('fake_username', 'fake_password');
 }
예제 #6
0
    public function index()
    {
        $server = new Server('outlook.office365.com');
        // $connection is instance of \Ddeboer\Imap\Connection
        $connection = $server->authenticate('*****@*****.**', 'Data1992');
        $mailbox = $connection->getMailbox('INBOX/Home Depot');
        $search = new SearchExpression();
        $search->addCondition(new Unseen());
        $messages = $mailbox->getMessages($search);
        foreach ($messages as $message) {
            $strip = str_replace(' ', '', strip_tags($message->getBodyHtml()));
            $value = strpos($strip, 'TOTAL$');
            //Check if its a return or a purchase
            if ($value == false) {
                $thing = 'TOTAL-$';
                $num = 7;
            } else {
                $thing = 'TOTAL$';
                $num = 6;
            }
            //TOTAL $__
            $first = strpos($strip, $thing);
            $space = strpos($strip, 'X', $first) - $first - $num;
            // $value = substr($strip, $first+5, 1);
            //Check if its a return or a purchase
            if ($value == false) {
                $amount = '-' . substr($strip, $first + $num, $space);
            } else {
                $amount = substr($strip, $first + $num, $space);
            }
            //FIND PO/JOPBNAME...attach expense to project..if not porject is 0 and user is promped to select a project.
            $po = strpos($strip, 'JOBNAME:');
            if (is_bool($po)) {
                $project = '0';
            } else {
                $spc = strpos($strip, 'PRO', $po) - $po - 14;
                $pro = substr($strip, $po + 8, $spc);
                $project_id = Project::where('id', $pro)->first();
            }
            //check if PROJECT NAME/ PO/JOBNAME from receipt exists in database, if not, project is 0
            if (is_null($project_id)) {
                $project = '0';
            } else {
                $project = $project_id->id;
            }
            Expense::insert(['amount_paid' => $amount, 'employee_id' => '5', 'paid_on' => date('Y-m-d'), 'Project_id' => $project, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"), 'reimbursment' => 2, 'office' => 2]);
            $attachments = $message->getAttachments();
            foreach ($attachments as $attachment) {
                $file = $attachment->getDecodedContent();
                $name = time() . 'expense.pdf';
                // $file->move('docs/expenses', $name);
                file_put_contents('docs/expenses/' . $name, $attachment->getDecodedContent());
                // $file = $request->file('file');
                $url = Expense::latest()->first();
                $url->receipt_url = $name;
                $url->save();
            }
            unset($project);
            unset($project_id);
            ?>
				<br>
				<?php 
        }
    }