function CopyMessageToDestination($dbh, $c, $d, $m) { $maxorder = GetMaxMessageOrder($d, $dbh); $query = "SELECT * FROM message WHERE message_id={$m}"; $result = mysql_query($query, $dbh); $row = mysql_fetch_array($result, MYSQL_NUM); $query = "INSERT INTO message VALUES ('',{$row['1']},'{$row['2']}','{$row['3']}','{$row['4']}','{$row['5']}','{$row['6']}',{$maxorder})"; $ins = mysql_query($query, $dbh); $nm = mysql_insert_id(); $query = "SELECT * FROM attachment WHERE message_id={$m}"; $result = mysql_query($query, $dbh); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $query = "INSERT INTO attachment VALUES ('',{$nm},'{$row['1']}',{$row['2']},'{$row['3']}',{$row['4']},{$row['5']},'{$row['6']}','{$row['7']}','{$row['8']}','{$row['9']}')"; $ins = mysql_query($query, $dbh); } }
$long = $coord[1]; } else { if (sizeof($coord) == 3 && $coord[0] != 0 && $coord[1] != 0) { $lat = $coord[0]; $long = $coord[1]; $datetime = $coord[2]; } } } $tags = GetTagsFromExif($upload); } else { $w = 0; $h = 0; } $message_date = date("Y-m-d H:i:s"); $maxorder = GetMaxMessageOrder($c, $dbh); $query = "INSERT INTO message (channel_id, message_date, message_sender, message_subject, message_order) VALUES ({$c},'" . $message_date . "','" . $alias . "','',{$maxorder})"; $result = mysql_query($query, $dbh); $current_message = mysql_insert_id(); $query = "INSERT INTO attachment (message_id, filename, content_type, original_filename,image_width,image_height,latitude,longitude,date_time) VALUES ({$current_message},'{$filename}','{$att_type}','{$filename}',{$w},{$h},'{$lat}','{$long}','{$datetime}')"; $result = mysql_query($query, $dbh); IncreaseFileIndex($c, $dbh); ProcessMessageTags($tags, $current_message, $dbh); $tags = ""; $msg = "File uploader ... file upload OK."; } } } } } else { $c = -1;
function CheckMessages($user, $pass, $c, $folder, $get_tags_from_subject, $server, $dbh, $tz, $get_user_from_message_subject, $get_date_from_exif, $convert_to_mp3, $servpath, $sample_rate, $channel_folder, $static_map_width, $static_map_height, $api_key, $get_reverse_geocoding, $ffmpeg_path) { if ($inbox = imap_open($server, $user, $pass)) { $total = imap_num_msg($inbox); for ($x = 1; $x <= $total; $x++) { $headers = imap_header($inbox, $x); $structure = imap_fetchstructure($inbox, $x); $sections = parse($structure); if (isset($headers->subject)) { $subject = DecodeSubject($headers->subject); } else { $subject = ""; } if ($subject == "ojovoz" && is_array($sections) && sizeof($sections) > 0) { $maxorder = GetMaxMessageOrder($c, $dbh); $query = "INSERT INTO message (channel_id, message_order) VALUES ({$c},{$maxorder})"; $result = mysql_query($query, $dbh); $current_message = mysql_insert_id(); $lat = ""; $long = ""; for ($y = 0; $y < sizeof($sections); $y++) { $type = $sections[$y]["type"]; $encoding = $sections[$y]["encoding"]; $filename = substr($complete_filename, 0, strrpos($complete_filename, ".")); $pid = $sections[$y]["pid"]; $attachment = imap_fetchbody($inbox, $x, $pid); if (strpos($sections[$y]["name"], ".jpg") > 0 && $type == "image/jpeg") { $subfolder = "/image/image"; $extension = ".jpg"; $att_type = 1; } else { if (strpos($sections[$y]["name"], ".wav") > 0 && $type == "application/octet-stream") { $subfolder = "/sound/sound"; $extension = ".wav"; $att_type = 2; } else { if (strpos($sections[$y]["name"], ".amr") > 0 && $type == "application/octet-stream") { $subfolder = "/sound/sound"; $extension = ".amr"; $att_type = 2; } else { if (strpos($sections[$y]["name"], ".mp3") > 0 && $type == "application/octet-stream") { $subfolder = "/sound/sound"; $extension = ".mp3"; $att_type = 2; } else { if (strpos($sections[$y]["name"], ".3gp") > 0 && $type == "application/octet-stream") { $subfolder = "/sound/sound"; $extension = ".3gp"; $att_type = 2; } else { if (strpos($sections[$y]["name"], ".mp4") > 0 && $type == "application/octet-stream") { $subfolder = "/video/video"; $extension = ".mp4"; $att_type = 3; } else { if (strpos($sections[$y]["name"], ".avi") > 0 && $type == "application/octet-stream") { $subfolder = "/video/video"; $extension = ".avi"; $att_type = 3; } else { if ($type == "text/plain" || $type == "text/html") { if ($encoding == "base64") { $text = trim(utf8_decode(imap_base64($attachment))); } else { $text = trim(utf8_decode(decode_ISO88591($attachment))); } $parts = explode(";", $text); $sender = $parts[0]; $date = formatDate($parts[1]); $lat = $parts[2]; if ($lat == "-1.0") { $lat = ""; } $long = $parts[3]; if ($long == "-1.0") { $long = ""; } $tags = $parts[4]; if ($tags == "null") { $tags = ""; } $query = "UPDATE message SET message_date='{$date}', message_sender='{$sender}' WHERE message_id = {$current_message}"; $result = mysql_query($query, $dbh); $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($attachment)); fclose($handle); if ($extension == ".jpg") { $sz = getimagesize("channels/" . $file); $w = $sz[0]; $h = $sz[1]; } else { if (($extension == ".amr" || $extension == ".3gp") && $convert_to_mp3 == true) { $file1 = $subfolder . $index . $extension; $file2 = $subfolder . $index . ".mp3"; ConvertAMRToMP3($file1, $file2, $servpath, $ffmpeg_path, $channel_folder, $folder, $sample_rate); $w = 0; $h = 0; $file = $folder . $file2; } else { $w = 0; $h = 0; } } $query = "INSERT INTO attachment (message_id, filename, content_type,image_width,image_height) VALUES ({$current_message},'{$file}','{$att_type}',{$w},{$h})"; $result = mysql_query($query, $dbh); IncreaseFileIndex($c, $dbh); } } if ($lat != "" && $long != "") { $query = "UPDATE attachment SET latitude='{$lat}', longitude='{$long}' WHERE message_id={$current_message}"; $result = mysql_query($query, $dbh); } $sections = NULL; ProcessMessageTags($tags, $current_message, $dbh); } imap_delete($inbox, $x); } imap_close($inbox, CL_EXPUNGE); } }