public function testPOP()
 {
     $this->protocol = new POP();
     $this->protocol->setMailserver('pop.gmail.com')->setPort(995)->setFolder('INBOX')->setSsl(true);
     $this->assertNotNull($this->protocol->connect($this->config->get('username'), $this->config->get('password')));
 }
 /**
  * Get a parameter of the config or the entire collection
  *
  * @param bool $key The key of the parameter
  * @return Collection
  */
 public final function getConfig($key = false)
 {
     return $key ? $this->config->get($key) : $this->config;
 }
 /**
  * Get attachments from email
  *
  * @param string $id email identifier
  *
  * @throws \SimpleMailReceiver\Exceptions\SimpleMailReceiverException
  * @return Collection
  */
 public function retrieveAttachments($id)
 {
     try {
         $attachments = new Collection();
         //init the catching
         $this->exceptionThrower->start();
         $structure = imap_fetchstructure($this->mailbox, $id);
         if (property_exists($structure, 'parts')) {
             foreach ($structure->parts as $key => $value) {
                 $encoding = $structure->parts[$key]->encoding;
                 if ($structure->parts[$key]->ifdparameters) {
                     $name = $structure->parts[$key]->dparameters[0]->value;
                     $message = imap_fetchbody($this->mailbox, $id, $key + 1);
                     if ($encoding == 0) {
                         $message = imap_8bit($message);
                     }
                     if ($encoding == 1) {
                         $message = imap_8bit($message);
                     }
                     if ($encoding == 2) {
                         $message = imap_binary($message);
                     }
                     if ($encoding == 3) {
                         $message = imap_base64($message);
                     }
                     if ($encoding == 4) {
                         $message = quoted_printable_decode($message);
                     }
                     if ($encoding == 5) {
                         $message = $message;
                     }
                     $this->exceptionThrower->stop();
                     $name_ext = pathinfo($name);
                     $attachment = new Attachment($name_ext['filename'], $message, $name_ext['extension'], sizeof($message));
                     $attachments->add($attachment);
                 }
             }
         }
         return $attachments;
     } catch (\Exception $e) {
         throw new SimpleMailReceiverException("Error retrieving attachments no: " . $id . " ." . $e->getMessage(), $e->getCode());
     }
 }