Beispiel #1
0
 /**
  *  Función que compruba si hay emails en las cuentas de correo que no hayan sido comprobados
  */
 public static function checkBouncedEmailsAccounts()
 {
     $emailStatusBouncedMessagesFromAccount = Preference::getValue('emailStatusBouncedMessagesFromAccount', 5, '0');
     // Comprobación para casos de errores o caídas del servidor, y no dejen bloquedo la comprobación de emails
     // si en 5 minutos no se ha liberado la variable, damos por hecho que se ha bloqueado y la liberamos
     $update = \DateTime::createFromFormat('Y-m-d H:i:s', $emailStatusBouncedMessagesFromAccount->updated_at);
     if ($emailStatusBouncedMessagesFromAccount->value_018 == '1' && date('U') - $update->getTimestamp() > 300) {
         Preference::setValue('emailStatusBouncedMessagesFromAccount', 5, '0');
     }
     // en el caso que el estado de envio esté activo, eso siginifica que hay una petición trabajando
     // cuando termine de hacerlo cambiaremos el estado de de comprobación de correos
     // para poder aceptar más peticiones, de esa manera nos aseguramos que no hayan
     // varias peticiones concurrentes comprobando mails.
     if ($emailStatusBouncedMessagesFromAccount->value_018 === '1') {
         //            todo, si devuelvo un json, al ejecutar el cron manualmente, no da ningún error, habría que filtrarlo
         //            return response()->json([
         //                'success'   => false,
         //                'message'   => 'at this moment, there is a process running'
         //            ]);
         exit;
     } else {
         Preference::setValue('emailStatusBouncedMessagesFromAccount', 5, '1');
     }
     // una vez comprobado que no hay mas procesos en ejecución, comenzamos a trabajar
     $accounts = EmailAccount::all();
     $patterns = EmailPattern::all();
     foreach ($accounts as $account) {
         $imapService = new ImapServices(['host' => $account->incoming_server_013, 'port' => $account->incoming_port_013, 'user' => $account->incoming_user_013, 'password' => Crypt::decrypt($account->incoming_pass_013), 'ssl' => $account->incoming_secure_013 == 'ssl' ? true : false]);
         // get total messages
         $nEmails = $imapService->getServer()->numMessages();
         // update n emails on account
         EmailAccount::builder()->where('id_013', $account->id_013)->update(['n_emails_013' => $nEmails]);
         // Get the last UID from email account
         if ($nEmails > 0) {
             $lastUidMessage = $imapService->getServer()->getUidByPositon($nEmails);
             // If the UID is grater than last UID manage, has to check account queue
             if ($lastUidMessage > $account->last_check_uid_013) {
                 //obtenemos la posición del siguiente mensaje sin chequear
                 $lastUidCheck = $account->last_check_uid_013;
                 $position = 0;
                 $i = 0;
                 // cuando obtengamos la posición del mensaje, será mayor que 0 y saldrá del bucle
                 // y si hemos hecho tantas o mas comprobaciones como emails hay, salimos del bucle
                 // sentencia para asegurarnos que no entramos en bucle infinito
                 while ($position < 1 && $i < $nEmails) {
                     // intentamos averiguar la posición del siguiente mensaje al último comprobado
                     $lastUidCheck++;
                     // si este UID no existe devolverá posición 0
                     $position = $imapService->getServer()->getPositonByUid($lastUidCheck);
                     // sumamos una vuelta para no entrar en bucle infinito
                     $i++;
                 }
                 // llamamos a la funcion que compruebe los correos es esa cuenta
                 Cron::checkBouncedMessagesFromAccount($imapService, $account, $patterns, $position - 1);
                 // solo comprobamo una cuenta
                 //break;
             }
         }
         // after check bounced messages or if there are not emails, close IMAP connection
         $imapService->getServer()->close();
         // if is the last email account, we freed the proccess
         if ($accounts->last()->id_013 == $account->id_013) {
             Preference::setValue('emailStatusBouncedMessagesFromAccount', 5, '0');
         }
     }
 }
 public function updateCustomRecord($parameters)
 {
     EmailPattern::where('id_049', $parameters['id'])->update(['name_049' => $this->request->input('name'), 'subject_049' => $this->request->has('subject') ? $this->request->input('subject') : null, 'operator_049' => $this->request->has('operator') ? $this->request->input('operator') : null, 'message_049' => $this->request->has('message') ? $this->request->input('message') : null, 'action_049' => $this->request->input('actionPattern')]);
 }
 public function run()
 {
     EmailPattern::insert([['name_049' => 'Undelivered Mail Returned to Sender (email account that you tried to reach is disabled)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'email account that you tried to reach is disabled', 'action_049' => 3], ['name_049' => 'Delivery Status Notification (Delivery to the following recipients failed)', 'subject_049' => 'Delivery Status Notification (Failure)', 'operator_049' => 'and', 'message_049' => 'Delivery to the following recipients failed', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (MAILBOX IS FULL)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'MAILBOX IS FULL', 'action_049' => 3], ['name_049' => 'Delivery Status Notification (Failure) (Unknown address error 550)', 'subject_049' => 'Delivery Status Notification (Failure)', 'operator_049' => 'and', 'message_049' => 'Unknown address error 550', 'action_049' => 3], ['name_049' => 'User unknown', 'subject_049' => null, 'operator_049' => null, 'message_049' => 'User unknown', 'action_049' => 3], ['name_049' => 'Failure notice (mailfolder is full)', 'subject_049' => 'failure notice', 'operator_049' => 'and', 'message_049' => 'mailfolder is full', 'action_049' => 3], ['name_049' => 'Failure notice (Remote host said: 451 unable to verify sender)', 'subject_049' => 'failure notice', 'operator_049' => 'and', 'message_049' => 'Remote host said: 451 unable to verify sender', 'action_049' => 3], ['name_049' => 'Warning: message (Delay reason: mailbox is full)', 'subject_049' => 'failure notice', 'operator_049' => 'and', 'message_049' => 'Delay reason: mailbox is full', 'action_049' => 3], ['name_049' => 'Mail delivery failed: returning message to sender (mailbox is full: retry timeout exceeded)', 'subject_049' => null, 'operator_049' => null, 'message_049' => 'mailbox is full: retry timeout exceeded', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (unknown in virtual mailbox)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'unknown in virtual mailbox', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (This is a spam mail)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'This is a spam mail', 'action_049' => 6], ['name_049' => 'Undelivered Mail Returned to Sender (Host or domain name not found)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'Host or domain name not found', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (Quota exceeded)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'Quota exceeded', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (mailbox unavailable)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'mailbox unavailable', 'action_049' => 3], ['name_049' => 'No se puede entregar (No se pudo encontrar la dirección de correo)', 'subject_049' => 'No se puede entregar', 'operator_049' => 'and', 'message_049' => 'No se pudo encontrar la', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (No such user)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'No such', 'action_049' => 3], ['name_049' => 'mailfolder is over the allowed quota', 'subject_049' => null, 'operator_049' => null, 'message_049' => 'mailfolder is over the allowed quota', 'action_049' => 3], ['name_049' => '550 Address unknown', 'subject_049' => null, 'operator_049' => null, 'message_049' => '550 Address unknown', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (permission denied)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'permission denied', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (Host or domain name not)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'Host or domain name not', 'action_049' => 3], ['name_049' => 'Undelivered Mail Returned to Sender (Address rejected)', 'subject_049' => 'Undelivered Mail Returned to Sender', 'operator_049' => 'and', 'message_049' => 'Address rejected', 'action_049' => 3]]);
 }