Esempio n. 1
0
    /**
     *
     */
    protected function send()
    {
        if (!attrib('to') || !attrib('body')) {
            pr(<<<'EOD'
------------------------------------------------------------
arguments:
    --to            send to email address
    --subject       email subject
    --body          email content message

example:
    php send --to xxx@gmail.com --subject "hello" --body "hi"
    php send --to xxx@gmail.com --body "$(cat message.txt)"
------------------------------------------------------------
EOD
);
            exit;
        }
        $getFrom = function () {
            $fromEmail = conf('gmail.email');
            $fromName = conf('gmail.name');
            return "{$fromName} <{$fromEmail}>";
        };
        $to = attrib('to');
        $subject = attrib('subject', 'not-subject');
        $body = attrib('body');
        $result = \GmailManager::sendMessage($getFrom(), $to, $subject, $body);
        if ($result) {
            pr('Send success');
        } else {
            pr('Send fail !');
        }
    }
Esempio n. 2
0
 /**
  *  
  */
 protected function webhook()
 {
     $status = attrib('status');
     switch (strtolower($status)) {
         case 'on':
             put('根據測試, 必須夾帶 crt 檔案才能正確設定 web hook, 請手動設定.');
             /*
             $telegram = new \Telegram\Bot\Api(conf('bot.token'));
             $response = $telegram->setWebhook([
                 'url' => conf('bot.hook_file')
             ]);
             put( $response );
             */
             return;
         case 'off':
             // 該指令關閉 web hook, 通常用於開發環境
             $telegram = new \Telegram\Bot\Api(conf('bot.token'));
             $response = $telegram->removeWebhook();
             put($response->getDecodedBody());
             return;
         default:
             break;
     }
     put('fail');
 }
 /**
  *  import all emails
  *      - 將 send 信件匯入, 然後刪除
  *      - 將 get 的未讀信信匯入, 設定成已讀
  *      - 導入 send 信件要早於 get, 奇怪的原因如下面 "NOTE" 寫的
  *
  *  NOTE: 一個待查的問題, 如果寄信給自己, 只會收到一封信, 然而 匯入 "get" & "send" 都會取得這封信, 這個會造成一些問題....
  *
  */
 protected function importAll()
 {
     if ("exec" !== attrib(0)) {
         pr('---- debug mode ---- (你必須要輸入參數 exec 才會真正執行)');
         exit;
     }
     di('log')->record('start PHP ' . phpversion());
     $show = [];
     $inboxes = new \Inboxes();
     // import "get", "send" emails
     $messages = array_merge(\GmailManager::getUnreadMessages(), \GmailManager::getSendMessages());
     // 時間為軸 舊 -> 新 排序
     $messageSortByTime = [];
     foreach ($messages as $message) {
         $time = strtotime($message['headers']['date']);
         $messageSortByTime[$time] = $message;
     }
     sort($messageSortByTime);
     //
     foreach ($messageSortByTime as $message) {
         $inbox = $this->makeInbox($message);
         $result = $inboxes->addInbox($inbox);
         if ($result) {
             if ('unread' == $message['customType']) {
                 // 將信件設定為 已讀
                 \GmailManager::setMessageLabelToIsRead($message['googleMessageId']);
             } else {
                 // 刪除該信件!!
                 \GmailManager::deleteMessage($message['googleMessageId']);
             }
         } else {
             $result = 'fail';
         }
         if ('unread' == $message['customType']) {
             $type = 'get from: ' . $inbox->getFromEmail();
         } else {
             $type = 'send to : ' . $inbox->getToEmail();
         }
         $show[] = [$message['googleMessageId'], $inbox->getMessageId(), $inbox->getSubject(), $type, date('Y-m-d H:i:s', $inbox->getEmailCreateTime()), $result];
     }
     if ($show) {
         table($show, ['google message id', 'message id', 'subject', 'from/to', 'date', 'result']);
     }
 }
Esempio n. 4
0
    /**
     *
     */
    protected function getEmail()
    {
        if (!attrib(0)) {
            pr(<<<'EOD'
------------------------------------------------------------
only arguments:
    id     (int)     get email by id
    "last" (string)  get last email

example:
    php get 10
    php get last
------------------------------------------------------------
EOD
);
            exit;
        }
        $id = attrib(0);
        $inboxes = new \Inboxes();
        // get by last
        if ('last' === $id) {
            $myInboxes = $inboxes->findInboxes(['_order' => 'id,DESC', '_itemsPerPage' => 1]);
            if (isset($myInboxes[0])) {
                $this->_show($myInboxes[0]);
            } else {
                pr('Inbox data not found');
            }
            exit;
        }
        // get by index
        $inbox = $inboxes->getInbox($id);
        if (!$inbox) {
            pr('Inbox data not found');
            exit;
        }
        $this->_show($inbox);
    }
Esempio n. 5
0
function formatxml($el, $depth)
{
    $ind = $depth * 10;
    echo "<div style='margin-left:{$ind};'>";
    if ($el->nodeType == 1) {
        if ($el->childNodes->length == 0) {
            echo "&lt;" . $el->tagName;
            attrib($el);
            echo "/>";
        } else {
            echo "&lt;" . $el->tagName;
            attrib($el);
            echo "><br/>";
            foreach ($el->childNodes as $child) {
                formatxml($child, $depth + 1);
            }
            echo "&lt;/" . $el->tagName . ">";
        }
    }
    if ($el->nodeType == 3) {
        echo "<span style='color:red'>" . $el->nodeValue . "</span><br/>";
    }
    echo "</div>";
}
Esempio n. 6
0
function formatxml($el, $depth, $namespaceuri)
{
    $ns = "";
    //	echo $el->lookupnamespaceURI(NULL);
    if (!($namespaceuri == $el->lookupnamespaceURI(NULL))) {
        $ns = "<span style='color:purple'> xmlns</span>=<span style='color:red'> '" . $el->lookupnamespaceURI(NULL) . "'</span> ";
    }
    $namespaceuri = $el->lookupnamespaceURI(NULL);
    $ind = $depth * 10;
    echo "<div style='margin-left:{$ind};' >";
    if ($el->nodeType == 1) {
        if ($el->childNodes->length == 0) {
            echo "&lt;" . $el->tagName;
            attrib($el);
            echo "/>";
        } else {
            echo "&lt;" . $el->tagName;
            echo $ns;
            attrib($el);
            echo "><br/>";
            foreach ($el->childNodes as $child) {
                formatxml($child, $depth + 1, $namespaceuri);
            }
            echo "&lt;/" . $el->tagName . ">";
        }
    }
    if ($el->nodeType == 3) {
        echo "<span style='color:red'>" . $el->nodeValue . "</span><br/>";
    }
    echo "</div>";
}