Пример #1
0
 /**
  * Execute the console command.
  *
  * @return bool
  */
 public function handle()
 {
     Log::info(get_class($this) . ': ' . 'Being called upon to receive an incoming e-mail');
     // Read from stdin (should be piped from cat or MDA)
     $fd = fopen('php://stdin', 'r');
     $rawEmail = '';
     while (!feof($fd)) {
         $rawEmail .= fread($fd, 1024);
     }
     fclose($fd);
     /*
      * save evidence onto disk
      */
     $evidence = new EvidenceSave();
     $evidenceData = $rawEmail;
     $evidenceFile = $evidence->save($evidenceData);
     if (!$evidenceFile) {
         Log::error(get_class($this) . ': ' . 'Error returned while asking to write evidence file, cannot continue');
         $this->exception($rawEmail);
     }
     if ($this->option('noqueue') == true) {
         // In debug mode we don't queue the job
         Log::debug(get_class($this) . ': ' . 'Queuing disabled. Directly handling message file: ' . $evidenceFile);
         $processer = new EmailProcess($evidenceFile);
         $processer->handle();
     } else {
         Log::info(get_class($this) . ': ' . 'Pushing incoming email into queue file: ' . $evidenceFile);
         $this->dispatch(new EmailProcess($evidenceFile));
     }
     Log::info(get_class($this) . ': ' . 'Successfully received the incoming e-mail');
     return true;
 }
Пример #2
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     Log::info(get_class($this) . ': ' . 'Being called upon to receive an incoming e-mail');
     // Read from stdin (should be piped from cat or MDA)
     $fd = fopen("php://stdin", "r");
     $rawEmail = "";
     while (!feof($fd)) {
         $rawEmail .= fread($fd, 1024);
     }
     fclose($fd);
     $filesystem = new Filesystem();
     $datefolder = Carbon::now()->format('Ymd');
     $path = storage_path() . '/mailarchive/' . $datefolder . '/';
     $file = Uuid::generate(4) . '.eml';
     $filename = $path . $file;
     if (!$filesystem->isDirectory($path)) {
         // If a datefolder does not exist, then create it or die trying
         if (!$filesystem->makeDirectory($path)) {
             Log::error(get_class($this) . ': ' . 'Unable to create directory: ' . $path);
             $this->exception($rawEmail);
         }
         chown($path, 'abuseio');
         chgrp($path, 'abuseio');
     }
     if ($filesystem->isFile($filename)) {
         Log::error(get_class($this) . ': ' . 'File already exists: ' . $path . $filename);
         $this->exception($rawEmail);
         chown($path . $filename, 'abuseio');
         chgrp($path . $filename, 'abuseio');
     }
     if ($filesystem->put($filename, $rawEmail) === false) {
         Log::error(get_class($this) . ': ' . 'Unable to write file: ' . $filename);
         $this->exception($rawEmail);
     }
     if ($this->option('noQueue') == true) {
         // In debug mode we don't queue the job
         Log::debug(get_class($this) . ': ' . 'Queuing disabled. Directly handling message file: ' . $filename);
         $processer = new EmailProcess($filename);
         $processer->handle();
     } else {
         Log::info(get_class($this) . ': ' . 'Pushing incoming email into queue file: ' . $filename);
         $this->dispatch(new EmailProcess($filename));
     }
     Log::info(get_class($this) . ': ' . 'Successfully received the incoming e-mail');
     return true;
 }