/** * @return Gmail */ public function initGmailConnection() { if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $this->output->writeln("Init Gmail Connection"); } $gmail = new Gmail($this->config); $gmail->getClient(); $this->gmail = $gmail; return $gmail; }
/** * Store it in the gmail service */ public function store() { $mail = new ezcMailComposer(); $first = true; foreach ($this->getPartnersSkypename() as $partner) { $address = new ezcMailAddress(empty($partner['email']) ? $partner['skypename'] . '@unknown.com' : $partner['email'], $partner['name']); if ($first && $partner['skypename']) { $mail->from = $address; $first = false; } else { $mail->addTo($address); } } // Specify the subject of the mail $mail->subject = $this->displayname; // Specify the body text of the mail $mail->htmlText = $this->toHtml(); // Generate the mail $mail->build(); $mail->setHeader("Date", date('r', $this->getMaxTimestamp())); $mailWithCorrectDate = preg_replace('/^Date:.*$/m', 'Date: ' . date('r', $this->getMaxTimestamp()), $mail->generate()); $msgbody = new Google_Service_Gmail_Message(); $msgbody->setRaw(rtrim(strtr(base64_encode($mailWithCorrectDate), '+/', '-_'), '=')); $msgbody->setLabelIds([$this->config['label']]); $service = new Google_Service_Gmail($this->gmail->getClient()); $service->users_messages->insert('me', $msgbody, ['internalDateSource' => 'dateHeader']); if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $this->output->writeln("Storing conversation with subject '{$mail->subject}' and date '" . date('r', $this->getMaxTimestamp()) . "'"); } }