function get_part($imap, $uid, $mimetype, $structure = false, $partNumber = false)
{
    if (!$structure) {
        //$imap_uid = imap_uid ($imap, $uid);
        //echo "$uid->".$uid;
        $structure = imap_fetchstructure($imap, $uid, FT_UID);
    }
    //echo "<br/>structure-><pre>".print_r($structure)."</pre>";
    if ($structure) {
        if ($mimetype == get_mime_type($structure)) {
            if (!$partNumber) {
                $partNumber = 1;
            }
            $text = imap_fetchbody($imap, $uid, $partNumber, FT_UID);
            switch ($structure->encoding) {
                case 3:
                    return imap_base64($text);
                case 4:
                    return imap_qprint($text);
                default:
                    return $text;
            }
        }
        // multipart
        if ($structure->type == 1) {
            foreach ($structure->parts as $index => $subStruct) {
                $prefix = "";
                if ($partNumber) {
                    $prefix = $partNumber . ".";
                }
                $data = get_part($imap, $uid, $mimetype, $subStruct, $prefix . ($index + 1));
                if ($data) {
                    return $data;
                }
            }
        }
    }
    return false;
}
Beispiel #2
0
function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false)
{
    if (!$structure) {
        $structure = imap_fetchstructure($stream, $msg_number);
    }
    if ($structure) {
        if ($mime_type == get_mime_type($structure)) {
            if (!$part_number) {
                $part_number = "1";
            }
            $text = imap_fetchbody($stream, $msg_number, $part_number);
            if ($structure->encoding == 3) {
                return imap_base64($text);
            } else {
                if ($structure->encoding == 4) {
                    return imap_qprint($text);
                } else {
                    return $text;
                }
            }
        }
        if ($structure->type == 1) {
            while (list($index, $sub_structure) = each($structure->parts)) {
                if ($part_number) {
                    $prefix = $part_number . '.';
                }
                $data = get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
                if ($data) {
                    return $data;
                }
            }
            // END OF WHILE
        }
        // END OF MULTIPART
    }
    // END OF STRUTURE
    return false;
}
 public function temp()
 {
     set_time_limit(4000);
     // Connect to gmail
     $imapPath = '{imap.gmail.com:993/imap/ssl}INBOX';
     $username = '******';
     $password = '******';
     $imap = imap_open($imapPath, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
     $numMessages = imap_num_msg($imap);
     for ($i = $numMessages; $i > $numMessages - 1; $i--) {
         $header = imap_header($imap, $i);
         $fromInfo = $header->from[0];
         $replyInfo = $header->reply_to[0];
         $details = array("fromAddr" => isset($fromInfo->mailbox) && isset($fromInfo->host) ? $fromInfo->mailbox . "@" . $fromInfo->host : "", "fromName" => isset($fromInfo->personal) ? $fromInfo->personal : "", "replyAddr" => isset($replyInfo->mailbox) && isset($replyInfo->host) ? $replyInfo->mailbox . "@" . $replyInfo->host : "", "subject" => isset($header->subject) ? $header->subject : "", "udate" => isset($header->udate) ? $header->udate : "");
         $uid = imap_uid($imap, $i);
     }
     $body = get_part($imap, $uid, "TEXT/HTML");
     // if HTML body is empty, try getting text body
     /*  if ($body == "") {
             $body = get_part($imap, $uid, "TEXT/PLAIN");
         }
         return $body;*/
     // return view('messages.che')->with('body',$body);
 }
Beispiel #4
0
 public function indenx()
 {
     //echo "<pre>";
     //print_r($_SERVER['HTTP_HOST']);
     //exit;
     $hostname = '{imap.gmail.com:993/imap/ssl}test';
     $username = '******';
     $password = '******';
     $inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
     /* grab emails */
     $emails = imap_search($inbox, 'ALL');
     $overview = imap_fetch_overview($inbox, 1, 0);
     print_r($overview);
     exit;
     /* if emails are returned, cycle through each... */
     if ($emails) {
         /* begin output var */
         $output = '';
         $values = '';
         /* put the newest emails on top */
         rsort($emails);
         /* for every email... */
         foreach ($emails as $email) {
             /* get information specific to this email */
             $overview = imap_fetch_overview($inbox, $email, 0);
             $message = get_part($inbox, $email, "TEXT/HTML");
             $attachments = '';
             //$message = imap_fetchbody($inbox,$email,2);
             //imap_fetchstructure($inbox, $email);
             $struct = imap_fetchstructure($inbox, $email);
             $contentParts = count($struct->parts);
             if ($contentParts >= 2) {
                 for ($i = 2; $i <= $contentParts; $i++) {
                     $att[$i - 2] = imap_bodystruct($inbox, $email, $i);
                 }
                 for ($k = 0; $k < sizeof($att); $k++) {
                     if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") {
                         if ($att[$k]->parameters[1]->value != "") {
                             $strFileName = $att[$k]->parameters[1]->value;
                             $strFileType = strrev(substr(strrev($strFileName), 0, 4));
                             $fileContent = imap_fetchbody($inbox, $email, 2);
                             downloadFile($strFileType, $strFileName, $fileContent);
                             $attachments .= $strFileName . ',';
                         }
                     } elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") {
                         $strFileName = $att[$k]->parameters[0]->value;
                         $strFileType = strrev(substr(strrev($strFileName), 0, 4));
                         $fileContent = imap_fetchbody($inbox, $email, 2);
                         //downloadFile($strFileType,$strFileName,$fileContent);
                         $attachments .= $strFileName . ',';
                     }
                 }
             }
         }
     }
     //	imap_msgno($inbox,$uid);
     //exit;
     $this->load->view('welcome_message');
 }
Beispiel #5
0
function email_to_commsy($mbox, $msgno)
{
    global $environment;
    global $portal_id_array;
    global $c_email_upload_email_account;
    $translator = $environment->getTranslationObject();
    $struct = imap_fetchstructure($mbox, $msgno);
    $header = imap_headerinfo($mbox, $msgno);
    $sender = $header->from[0]->mailbox . '@' . $header->from[0]->host;
    $subject = $header->subject;
    #$body = imap_fetchbody($mbox,$msgno,1);
    // just use the plain part of the e-mail
    $body_plain = get_part($mbox, $msgno, "TEXT/PLAIN");
    $body_html = get_part($mbox, $msgno, "TEXT/HTML");
    $body_is_plain = true;
    if (!empty($body_plain)) {
        $body = $body_plain;
    } else {
        $body_is_plain = false;
        $body = $body_html;
    }
    // get additional Information from e-mail body
    $translator->setSelectedLanguage('de');
    $translation['de']['password'] = $translator->getMessage('EMAIL_TO_COMMSY_PASSWORD');
    $translation['de']['account'] = $translator->getMessage('EMAIL_TO_COMMSY_ACCOUNT');
    $translator->setSelectedLanguage('en');
    $translation['en']['password'] = $translator->getMessage('EMAIL_TO_COMMSY_PASSWORD');
    $translation['en']['account'] = $translator->getMessage('EMAIL_TO_COMMSY_ACCOUNT');
    $account = '';
    $secret = '';
    $body = preg_replace('/\\r\\n|\\r/', "\n", $body);
    $body_array = explode("\n", $body);
    $temp_body = array();
    $with_footer = false;
    $footer_line = 0;
    $index = 0;
    foreach ($body_array as $body_line) {
        if (strip_tags($body_line) == '-- ') {
            // start of e-mail signature
            $with_footer = true;
            $footer_line = $index;
        }
        $index++;
    }
    $index = 0;
    $secret_found = false;
    $account_found = false;
    foreach ($body_array as $body_line) {
        if ($with_footer and $index == $footer_line) {
            break;
        }
        if (!empty($body_line)) {
            $body_line = strip_tags($body_line);
            if (stristr($body_line, $translation['de']['account']) and !$account_found) {
                $temp_body_line = str_ireplace($translation['de']['account'] . ':', '', $body_line);
                $temp_body_line_array = explode(' ', trim($temp_body_line));
                $account = $temp_body_line_array[0];
                $account_found = true;
            } else {
                if (stristr($body_line, $translation['en']['account']) and !$account_found) {
                    $temp_body_line = str_ireplace($translation['en']['account'] . ':', '', $body_line);
                    $temp_body_line_array = explode(' ', trim($temp_body_line));
                    $account = $temp_body_line_array[0];
                    $account_found = true;
                } else {
                    if (stristr($body_line, $translation['de']['password']) and !$secret_found) {
                        $temp_body_line = str_ireplace($translation['de']['password'] . ':', '', $body_line);
                        $temp_body_line_array = explode(' ', trim($temp_body_line));
                        $secret = $temp_body_line_array[0];
                        $secret_found = true;
                    } else {
                        if (stristr($body_line, $translation['en']['password']) and !$secret_found) {
                            $temp_body_line = str_ireplace($translation['en']['password'] . ':', '', $body_line);
                            $temp_body_line_array = explode(' ', trim($temp_body_line));
                            $secret = $temp_body_line_array[0];
                            $secret_found = true;
                        } else {
                            $temp_body[] = $body_line;
                        }
                    }
                }
            }
        } else {
            $temp_body[] = $body_line;
        }
        $index++;
    }
    $body = implode("\n", $temp_body);
    foreach ($portal_id_array as $portal_id) {
        $environment->setCurrentPortalID($portal_id);
        $user_manager = $environment->getUserManager();
        $user_manager->setContextArrayLimit($portal_id);
        $user_manager->setEMailLimit($sender);
        $user_manager->select();
        $user_list = $user_manager->get();
        $user = $user_list->getfirst();
        $found_users = array();
        while ($user) {
            if ($account != '') {
                if ($account == $user->getUserID()) {
                    $found_users[] = $user;
                }
            } else {
                $found_users[] = $user;
            }
            $user = $user_list->getnext();
        }
        foreach ($found_users as $found_user) {
            $private_room_user = $found_user->getRelatedPrivateRoomUserItem();
            $private_room = $private_room_user->getOwnRoom();
            $translator->setSelectedLanguage($private_room->getLanguage());
            if ($private_room->getEmailToCommSy()) {
                $email_to_commsy_secret = $private_room->getEmailToCommSySecret();
                $result_mail = new cs_mail();
                $result_mail->set_to($sender);
                $result_mail->set_from_name('CommSy');
                // $result_mail->set_from_email('*****@*****.**');
                $errors = array();
                if ($secret == $email_to_commsy_secret) {
                    $private_room_id = $private_room->getItemID();
                    $files = array();
                    if ($struct->subtype == 'PLAIN') {
                    } else {
                        if ($struct->subtype == 'MIXED') {
                            // with attachment
                            $contentParts = count($struct->parts);
                            if ($contentParts >= 2) {
                                for ($i = 2; $i <= $contentParts; $i++) {
                                    $att[$i - 2] = imap_bodystruct($mbox, $msgno, $i);
                                }
                                for ($k = 0; $k < sizeof($att); $k++) {
                                    $strFileName = $att[$k]->dparameters[0]->value;
                                    $strFileType = strrev(substr(strrev($strFileName), 0, 4));
                                    $fileContent = imap_fetchbody($mbox, $msgno, $k + 2);
                                    $file = getFile($strFileType, $strFileName, $fileContent);
                                    // copy file to temp
                                    $temp_file = 'var/temp/' . $strFileName . '_' . getCurrentDateTimeInMySQL();
                                    file_put_contents($temp_file, $file);
                                    $temp_array = array();
                                    $temp_array['name'] = utf8_encode($strFileName);
                                    $temp_array['tmp_name'] = $temp_file;
                                    $temp_array['file_id'] = $temp_array['name'] . '_' . getCurrentDateTimeInMySQL();
                                    $temp_array['file_size'] = filesize($temp_file);
                                    $files[] = $temp_array;
                                }
                            }
                        }
                    }
                    $environment->setCurrentContextID($private_room_id);
                    $environment->setCurrentUser($private_room_user);
                    $environment->unsetLinkModifierItemManager();
                    $material_manager = $environment->getMaterialManager();
                    $material_item = $material_manager->getNewItem();
                    $material_item->setTitle(trim(str_replace($email_to_commsy_secret . ':', '', $subject)));
                    $material_item->setDescription($body);
                    // attach files to the material
                    $file_manager = $environment->getFileManager();
                    $file_manager->setContextLimit($private_room_id);
                    $portal_item = $environment->getCurrentPortalItem();
                    $portal_max_file_size = $portal_item->getMaxUploadSizeInBytes();
                    $file_id_array = array();
                    $error['files_to_large'] = array();
                    foreach ($files as $file) {
                        if ($file["file_size"] <= $portal_max_file_size) {
                            $file_item = $file_manager->getNewItem();
                            $file_item->setTempKey($file["file_id"]);
                            $file_item->setPostFile($file);
                            $file_item->save();
                            $file_id_array[] = $file_item->getFileID();
                        } else {
                            $error['files_to_large'][] = array('name' => $file['name'], 'size' => $file["file_size"]);
                        }
                    }
                    $material_item->setFileIDArray($file_id_array);
                    $material_item->save();
                    // send e-mail with 'material created in your private room' back to sender
                    $file = $_SERVER['PHP_SELF'];
                    $file = str_replace('cron_email_upload', 'commsy', $file);
                    $curl_text = 'http://' . $c_commsy_domain . $file . '?cid=';
                    #$params['iid'] = $material_item->getItemID();
                    #$link_to_new_material = curl($private_room_id, 'material', 'detail', $params);
                    //$link_to_new_material = '<a href="'.$curl_text.$private_room_id.'&amp;mod=material&amp;fct=detail&amp;iid='.$material_item->getItemID().'">'.$material_item->getTitle().'</a>';
                    $result_body = $translator->getMessage('EMAIL_TO_COMMSY_RESULT_SUCCESS', $private_room_user->getFullName()) . "\n\n";
                    if (!empty($error['files_to_large'])) {
                        $files_to_large = '';
                        foreach ($error['files_to_large'] as $file_to_large) {
                            $files_to_large .= '- ' . $file_to_large['name'] . ' (' . round($file_to_large['size'] / (1024 * 1024), 2) . ' MB)' . "\n";
                        }
                        $result_body .= $translator->getMessage('EMAIL_TO_COMMSY_RESULT_FILES_TO_LARGE', $portal_max_file_size / (1024 * 1024), $files_to_large) . "\n\n";
                    }
                    $result_body .= $translator->getMessage('EMAIL_TO_COMMSY_RESULT_REGARDS');
                    $result_mail->set_subject('Upload2CommSy - erfolgreich');
                    $result_mail->set_message($result_body);
                } else {
                    // send e-mail with 'password or subject not correct' back to sender
                    $result_body = $translator->getMessage('EMAIL_TO_COMMSY_RESULT_FAILURE', $private_room_user->getFullName(), $translator->getMessage('EMAIL_TO_COMMSY_PASSWORD'));
                    $result_mail->set_subject('Upload2CommSy - fehlgeschlagen');
                    $result_mail->set_message($result_body);
                }
                #$result_mail->setSendAsHTML();
                $result_mail->send();
            }
        }
    }
    // mark e-mail for deletion
    imap_delete($mbox, $msgno);
}
}
function get_part($file, $searchfor, $name, $start)
{
    // get the file contents, assuming the file to be readable (and exist)
    $contents = file_get_contents($file);
    // escape special characters in the query
    $pattern = preg_quote($searchfor, '/');
    // finalise the regular expression, matching the whole line
    $pattern = "/^.*{$pattern}.*\$/m";
    // search, and store all matching occurences in $matches
    if (preg_match_all($pattern, $contents, $matches)) {
        $text = implode("\n", $matches[0]);
        //echo $text;
        replace_in_file($file, $text, $start . '="' . $name . '"');
        //replaceInFile($text, 'blog.title='+$name, $file);
    } else {
        echo "No matches found";
    }
}
get_part($file, $searchtitle, $title, $searchtitle);
get_part($file, $searchdescription, $description, $searchdescription);
get_part($file, $searchabout, $about, $searchabout);
get_part($file, $searchurl, $url, $searchurl);
get_part($file, $searchperpage, $perpage, $searchperpage);
get_part($file, $searchhost, $host, $searchhost);
get_part($file, $searchuser, $user, $searchuser);
get_part($file, $searchpassword, $password, $searchpassword);
get_part($file, $searchdatabase, $database, $searchdatabase);
get_part($file, $searchtheme, $theme, $searchtheme);
get_part($file, $searchdisqus, $disqus, $searchdisqus);
                    <p><?php 
get_text($the_video_description);
?>
</p>
                </div>
                
                <div class="right">
                    <a class="icon-twitter button" href="https://twitter.com/intent/tweet?text=&quot;<?php 
get_part($the_video_title);
?>
&quot;%20<?php 
get_part($the_video_permalink);
?>
%20via%20&#64;<?php 
get_setting($profile_twitter);
?>
" data-dnt="true" title="Share on Twitter"></a>
                    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
                    <a class="icon-facebook button" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2F<?php 
get_part($the_video_permalink);
?>
" target="_blank" title="Share on Facebook"></a>
                    <a class="icon-google-plus button" title="Share on Google" href="https://plus.google.com/share?url=<?php 
get_part($the_video_permalink);
?>
" onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"></a>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="<?php 
get_part($the_video_id);
?>
" class="block <?php 
get_part($the_video_status);
?>
">
    <div class="screenshot">
        <a href="<?php 
get_part($the_video_permalink);
?>
">
            <img src="<?php 
get_part($the_video_thumbnail);
?>
" />
        </a>
    </div>
    
    <h2><?php 
limit_text($the_video_title, '25');
?>
</h2>
    <p><?php 
limit_text($the_video_description, '70');
?>
</p>
</div>
Beispiel #9
0
function get_part($imap, $uid, $mimetype, $structure = false, $partNumber = false)
{
    if (!$structure) {
        $structure = imap_fetchstructure($imap, $uid, FT_UID);
    }
    if ($structure) {
        if ($mimetype == get_mime_type($structure)) {
            if (!$partNumber) {
                $partNumber = 1;
            }
            $text = imap_fetchbody($imap, $uid, $partNumber, FT_UID);
            switch ($structure->encoding) {
                case 3:
                    return imap_base64($text);
                case 4:
                    return imap_qprint($text);
                default:
                    return $text;
            }
        }
        /*/ multipart */
        if ($structure->type == 1) {
            foreach ($structure->parts as $index => $subStruct) {
                $prefix = "";
                if ($partNumber) {
                    $prefix = $partNumber . ".";
                }
                $imap = '';
                $data = get_part($imap, $uid, $mimetype, $subStruct, $prefix . ($index + 1));
                if ($data) {
                    return $data;
                }
            }
        }
    }
    return false;
}
Beispiel #10
0
function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false)
{
    global $CONFIG;
    global $disable_iconv;
    if (!$structure) {
        $structure = imap_fetchstructure($stream, $msg_number);
    }
    if ($structure) {
        $charset = "";
        foreach ($structure->parameters as $param) {
            if ($param->attribute == "CHARSET") {
                $charset = $param->value;
                if ($charset == "UTF-8") {
                    $charset = "";
                }
            }
        }
        if ($mime_type == get_mime_type(&$structure)) {
            if (!$part_number) {
                $part_number = "1";
            }
            $text = imap_fetchbody($stream, $msg_number, $part_number);
            if ($structure->encoding == 3) {
                $text = imap_base64($text);
            } else {
                if ($structure->encoding == 4) {
                    $text = imap_qprint($text);
                }
            }
            if ($charset && function_exists("iconv") && !$disable_iconv) {
                $text = iconv($charset, $CONFIG["Charset"], $text);
            }
            if ($charset && !$GLOBALS["mailcharset"]) {
                $GLOBALS["mailcharset"] = $charset;
            }
            return $text;
        }
        if ($structure->type == 1) {
            while (list($index, $sub_structure) = each($structure->parts)) {
                if ($part_number) {
                    $prefix = $part_number . ".";
                }
                $data = get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . $index + 1);
                if ($data) {
                    return $data;
                }
            }
        }
    }
    return false;
}