} } } else { $email['message'] = trim($email['message']); if ($email['content_type'] == 'text/html') { $email['message'] = str_replace("\n", "", $email['message']); $email['message'] = preg_replace('/<br(.*?)>/i', "\n", $email['message']); $email['message'] = trim(strip_tags($email['message'])); } } // Finally, Sanitize $email['from'] = $trellis->sanitize_data(imap_utf8($email['from'])); $email['nickname'] = $trellis->sanitize_data(imap_utf8($email['nickname'])); $email['to'] = $trellis->sanitize_data(imap_utf8($email['to'])); $email['subject'] = $trellis->sanitize_data(imap_utf8($email['subject'])); $email['message'] = $trellis->sanitize_data(utf8_encode(decode_ISO88591(imap_utf8($email['message'])))); if (!$email['nickname']) { $email['nickname'] = $email['from']; } if (!$email['from'] || !$email['to'] || !$email['subject'] || !$email['message']) { exit; } if (!$trellis->validate_email($email['from'])) { exit; } #============================= # Find Department #============================= $trellis->core->db->construct(array('select' => 'all', 'from' => 'departments', 'where' => array(array('email_pipe', '=', 1), array('incoming_email', '=', $email['to'], 'and')), 'limit' => array(0, 1))); $trellis->core->db->execute(); if (!$trellis->core->db->get_num_rows()) {
function ParseMultipart($type, $m, $a, $c, $folder, $tags, $dbh, $convert_to_mp3, $servpath, $sample_rate, $channel_folder, $static_map_width, $static_map_height, $api_key, $get_reverse_geocoding) { if (strpos($type, "mixed") > 0) { $multipart = GetMultipart($a); } elseif (strpos($type, "alternative") > 0) { $multipart = GetMultipartAlt($a); } if (sizeof($multipart) > 0) { $date_done = false; for ($mi = 0; $mi < sizeof($multipart); $mi++) { $mtype = $multipart[$mi]["type"]; $mattach = $multipart[$mi]["attachment"]; $original_filename = $multipart[$mi]["name"]; if ($mtype == "jpg" || $mtype == "jpe") { $subfolder = "/image/image"; $extension = ".jpg"; $att_type = 1; } elseif ($mtype == "wav") { $subfolder = "/sound/sound"; $extension = ".wav"; $att_type = 2; } elseif ($mtype == "amr") { $subfolder = "/sound/sound"; $extension = ".amr"; $att_type = 2; } elseif ($mtype == "mp3") { $subfolder = "/sound/sound"; $extension = ".mp3"; $att_type = 2; } elseif ($mtype == "3gp") { $subfolder = "/video/video"; $extension = ".3gp"; $att_type = 3; } elseif ($mtype == "mp4") { $subfolder = "/video/video"; $extension = ".mp4"; $att_type = 3; } elseif ($mtype == "avi") { $subfolder = "/video/video"; $extension = ".avi"; $att_type = 3; } elseif ($mtype == "txt" || $mtype == "text/plain") { $att_type = 0; $text = trim(utf8_decode(decode_ISO88591($mattach))); //tagging from mobile if ($tags == "") { $parts = ExtractTagsFromText($text); $text = $parts[0]; $tags = $parts[1]; } // $text = urlencode($text); $query = "UPDATE message SET message_text = '{$text}' WHERE message_id = {$m}"; $result = mysql_query($query, $dbh); } else { $att_type = 0; } if ($att_type > 0) { $index = GetMaxFileIndex($c, $dbh); $file = $folder . $subfolder . $index . $extension; $handle = fopen("channels/" . $file, "wb"); $ok = fwrite($handle, imap_base64($mattach)); fclose($handle); if ($extension == ".jpg") { $sz = getimagesize("channels/" . $file); $w = $sz[0]; $h = $sz[1]; if ($get_date_from_exif && !$date_done) { GetMessageDateFromExif("channels/" . $file, $m, $dbh); $date_done = true; } } else { if ($extension == ".amr" && $convert_to_mp3 == true) { $file1 = $subfolder . $index . $extension; $file2 = $subfolder . $index . ".mp3"; ConvertAMRToMP3($file1, $file2, $servpath, $channel_folder, $folder, $sample_rate); $w = 0; $h = 0; $file = $folder . $file2; } else { $w = 0; $h = 0; } } //GeoZexe: from filename or exif $lat = ""; $long = ""; $datetime = ""; /* $coord=GetCoordinatesFromFilename($original_filename); */ //if (sizeof($coord)==0) { if ($att_type == 1) { $coord = GetCoordinatesFromExif("channels/" . $file); //} if (sizeof($coord) == 1) { $datetime = $coord[0]; } else { if (sizeof($coord) == 2 && $coord[0] != 0 && $coord[1] != 0) { $lat = $coord[0]; $long = $coord[1]; } else { if (sizeof($coord) == 3 && $coord[0] != 0 && $coord[1] != 0) { $lat = $coord[0]; $long = $coord[1]; $datetime = $coord[2]; } } } if ($lat != "" && $long != "" && $get_reverse_geocoding == true) { $address = GetReverseGeocoding($lat, $long); } $tags_exif = GetTagsFromExif("channels/" . $file); if ($tags == "") { $tags = $tags_exif; } else { $tags .= "," . $tags_exif; } } $is_published = GetPublishedDefault($c, $dbh); $query = "INSERT INTO attachment (message_id, filename, content_type, original_filename,image_width,image_height,latitude,longitude,date_time,map_address,is_published) VALUES ({$m},'{$file}','{$att_type}','{$original_filename}',{$w},{$h},'{$lat}','{$long}','{$datetime}','{$address}',{$is_published})"; $result = mysql_query($query, $dbh); /* if ($lat!="" && $long!="") { $attachment_id=mysql_insert_id(); $map_filename=GrabMapImage($lat,$long,$attachment_id,$static_map_width,$api_key); if ($map_filename!="") { $query="UPDATE attachment SET map_filename = '$map_filename' WHERE attachment_id=$attachment_id"; $result = mysql_query($query, $dbh); } }*/ IncreaseFileIndex($c, $dbh); } } } return $tags; }