Example #1
0
}
class VKPoster
{
    public function post($to, $message)
    {
        $credentialsPath = expandHomeDirectory('~/.config/email-to-vk-vk.json');
        if (file_exists($credentialsPath)) {
            $accessToken = file_get_contents($credentialsPath);
        } else {
            // Request authorization from the user.
            // Let's pretend we are IPad application 8-)
            $authUrl = 'https://oauth.vk.com/authorize?client_id=3682744&v=5.7&scope=wall,offline&redirect_uri=http://oauth.vk.com/blank.html&display=page&response_type=token';
            printf("Open the following link in your browser:\n%s\n", $authUrl);
            print 'Enter access token: ';
            $accessToken = trim(fgets(STDIN));
            // Store the credentials to disk.
            if (!file_exists(dirname($credentialsPath))) {
                mkdir(dirname($credentialsPath), 0700, true);
            }
            file_put_contents($credentialsPath, $accessToken);
            printf("Credentials saved to %s\n", $credentialsPath);
        }
        return file_get_contents('https://api.vk.com/method/wall.post?owner_id=' . $to . '&from_group=1&message=' . urlencode($message) . '&access_token=' . $accessToken);
    }
}
$gmail = new MailParser();
$messages = $gmail->getEmails('*****@*****.**');
$vk = new VKPoster();
foreach ($messages as $m) {
    var_dump($vk->post(-104550496, $m));
}
Example #2
0
 function parseMail($input_file)
 {
     global $argv;
     //DBG("parseMail start");
     if (!($mp = new MailParser($input_file))) {
         $this->setError('Error In MailParser');
         //DBG("parseMail error1: ".$mp->getErrorMessage());
         return false;
     } elseif ($mp->isError()) {
         $this->setError('Error In MailParser ' . $mp->getErrorMessage());
         //DBG("parseMail error2: ".$mp->getErrorMessage());
         // even if it is an error, try to get the address of the sender so we
         // can send him back the error
         $this->FromEmail = $mp->getFromEmail();
         return false;
     }
     $this->FromEmail = $mp->getFromEmail();
     //DBG("email: ".$this->FromEmail);
     //echo ")()()()()()()".$this->FromEmail."(*(*(*(*(*";
     //
     //subjects are in this required format: '[group - Forum][123456] My Subject'
     //where 123456 is the msg_id of the forum message.
     //we parse that ID to get the forum and thread that this should post to
     //
     $subj = $mp->getSubject();
     //DBG("mp headers: ".implode("**\n",$mp->headers));
     //DBG("mp body: ".$mp->body);
     //DBG("SUBJ: ".$subj);
     //DBG("BODY: ".$mp->getBody());
     /*
     		$parent_start = (strpos($subj,'[',(strpos($subj,'[')+1))+1);
     		$parent_end = (strpos($subj,']',$parent_start)-1);
     		$this->Parent = substr($subj,$parent_start,($parent_end-$parent_start+1));
     		if (!$this->Parent || !is_numeric($this->Parent)) {
     //			$argv[1] - listname
     //			echo "No Parent ".$argv[0]."||".$argv[1];
     			$this->Parent=0;
     			$this->Subject = addslashes($subj);
     //			$this->setError('No Valid Parent ID Found in Subject Line');
     //			return false;
     		} else {
     //			echo "Parent: ".$this->Parent."||".$argv[0]."||".$argv[1];
     			$this->Subject = addslashes(substr($subj,$parent_end+3));
     		}
     */
     if (ereg('(\\[)([0-9]*)(\\])', $subj, $arr)) {
         $this->Parent = $arr[2];
         $parent_end = strpos($subj, '[' . $arr[2] . ']') + strlen('[' . $arr[2] . ']');
         $this->Subject = addslashes(substr($subj, $parent_end));
     } else {
         $this->Subject = addslashes($subj);
         $this->Parent = 0;
     }
     $this->Body =& addslashes($mp->getBody());
     //DBG( "body1:". $this->Body);
     $begin = strpos($this->Body, FORUM_MAIL_MARKER);
     if ($begin === false) {
         //do nothing
         return true;
     }
     // get the part of the message located after the marker
     $this->Body = substr($this->Body, $begin + strlen(FORUM_MAIL_MARKER));
     //DBG( "body2:". $this->Body);
     // now look for the ending marker
     $end = strpos($this->Body, FORUM_MAIL_MARKER);
     if ($end === false) {
         return true;
     }
     $message = substr($this->Body, 0, $end);
     $message = trim($message);
     // maybe the last line was "> (FORUM_MAIL_MARKER)". In that case, delete the last ">"
     $message = preg_replace('/>$/', '', $message);
     $this->Message = $message;
     return true;
 }
Example #3
0
 private static function _moveMail($strFile, $strDest = MAIL_ARCHIVED_DIR)
 {
     // move mail file to archived directory
     $strIncomingFile = MAIL_DIR_PATH . MAIL_INCOMING_DIR . '/' . $strFile;
     $strArchiveFile = MailParser::generateHashDir($strDest) . '/' . $strFile;
     system("mv " . $strIncomingFile . " " . $strArchiveFile);
 }
Example #4
0
 function parseMail($input_file)
 {
     global $argv;
     if (!($mp = new MailParser($input_file))) {
         $this->setError('Error In MailParser');
         return false;
     } elseif ($mp->isError()) {
         $this->setError('Error In MailParser ' . $mp->getErrorMessage());
         // even if it is an error, try to get the address of the sender so we
         // can send him back the error
         $this->FromEmail = $mp->getFromEmail();
         return false;
     }
     $this->FromEmail = $mp->getFromEmail();
     //
     //subjects are in this required format: '[group - tracker_name][123456] My Subject'
     //where 123456 is the artifact_id of the artifact message.
     //we parse that ID to get the artifact that this should post to
     //
     $subj = $mp->getSubject();
     if (ereg('(\\[)([0-9]*)(\\])', $subj, $arr)) {
         $this->ArtifactId = $arr[2];
         $artifactid_end = strpos($subj, '[' . $arr[2] . ']') + strlen('[' . $arr[2] . ']');
         $this->Subject = addslashes(substr($subj, $artifactid_end));
     } else {
         $this->Subject = addslashes($subj);
         $this->ArtifactId = 0;
         // Not supported at the moment
         $this->setError("ArtifactId needed at the moment. Artifact creation not supported");
         return false;
     }
     $body = addslashes($mp->getBody());
     // find first occurrence of the marker in the message
     $begin = strpos($body, ARTIFACT_MAIL_MARKER);
     if ($begin === false) {
         $this->setError("Response message wasn't found in your mail. Please verify that " . "you entered your message between the correct text markers." . "\nYour message was:" . "\n" . $mp->getBody());
         return false;
     }
     // get the part of the message located after the marker
     $body = substr($body, $begin + strlen(ARTIFACT_MAIL_MARKER));
     // now look for the ending marker
     $end = strpos($body, ARTIFACT_MAIL_MARKER);
     if ($end === false) {
         $this->setError("Response message wasn't found in your mail. Please verify that " . "you entered your message between the correct text markers." . "\nYour message was:" . "\n" . $mp->getBody());
         return false;
     }
     $message = substr($body, 0, $end);
     $message = trim($message);
     // maybe the last line was "> (ARTIFACT_MAIL_MARKER)". In that case, delete the last ">"
     $message = preg_replace('/>$/', '', $message);
     $this->Message = $message;
     return true;
 }