| 1 | <? |
| 2 | /** |
| 3 | ** mailbox.php |
| 4 | ** |
| 5 | ** This contains functions that request information about a mailbox. Including |
| 6 | ** reading and parsing headers, getting folder information, etc. |
| 7 | ** |
| 8 | **/ |
| 9 | |
| 10 | function selectMailbox($imapConnection, $mailbox, &$numberOfMessages) { |
| 11 | // select mailbox |
| 12 | fputs($imapConnection, "mailboxSelect SELECT \"$mailbox\"\n"); |
| 13 | $data = imapReadData($imapConnection, "mailboxSelect"); |
| 14 | for ($i = 0; $i < count($data); $i++) { |
| 15 | if (substr(Chop($data[$i]), -6) == "EXISTS") { |
| 16 | $array = explode(" ", $data[$i]); |
| 17 | $numberOfMessages = $array[1]; |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | function unseenMessages($imapConnection, &$numUnseen) { |
| 23 | fputs($imapConnection, "1 SEARCH UNSEEN NOT DELETED\n"); |
| 24 | $read = fgets($imapConnection, 1024); |
| 25 | $unseen = false; |
| 26 | |
| 27 | if (strlen($read) > 10) { |
| 28 | $unseen = true; |
| 29 | $ary = explode(" ", $read); |
| 30 | $numUnseen = count($ary) - 2; |
| 31 | } |
| 32 | else { |
| 33 | $unseen = false; |
| 34 | $numUnseen = 0; |
| 35 | } |
| 36 | |
| 37 | $read = fgets($imapConnection, 1024); |
| 38 | return $unseen; |
| 39 | } |
| 40 | |
| 41 | /** This function sends a request to the IMAP server for headers, 50 at a time |
| 42 | ** until $end is reached. I originally had it do them all at one time, but found |
| 43 | ** it slightly faster to do it this way. |
| 44 | ** |
| 45 | ** Originally we had getMessageHeaders get the headers for one message at a time. |
| 46 | ** Doing it in bunches gave us a speed increase from 9 seconds (for a box of 800 |
| 47 | ** messages) to about 3.5 seconds. |
| 48 | **/ |
| 49 | function getMessageHeaders($imapConnection, $start, $end, &$from, &$subject, &$date) { |
| 50 | $rel_start = $start; |
| 51 | if (($start > $end) || ($start < 1)) { |
| 52 | echo _("Error in message header fetching. Start message: "). $start, _("End message: "). "$end<BR>"; |
| 53 | exit; |
| 54 | } |
| 55 | |
| 56 | $pos = 0; |
| 57 | while ($rel_start <= $end) { |
| 58 | if ($end - $rel_start > 50) { |
| 59 | $rel_end = $rel_start + 49; |
| 60 | } else { |
| 61 | $rel_end = $end; |
| 62 | } |
| 63 | fputs($imapConnection, "messageFetch FETCH $rel_start:$rel_end RFC822.HEADER.LINES (From Subject Date)\n"); |
| 64 | $read = fgets($imapConnection, 1024); |
| 65 | |
| 66 | while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) { |
| 67 | |
| 68 | if (substr($read, 0, 5) == "From:") { |
| 69 | $read = encodeEmailAddr("$read"); |
| 70 | $from[$pos] = substr($read, 5, strlen($read) - 6); |
| 71 | } |
| 72 | else if (substr($read, 0, 5) == "Date:") { |
| 73 | $read = ereg_replace("<", "<", $read); |
| 74 | $read = ereg_replace(">", ">", $read); |
| 75 | $date[$pos] = substr($read, 5, strlen($read) - 6); |
| 76 | } |
| 77 | else if (substr($read, 0, 8) == "Subject:") { |
| 78 | $read = ereg_replace("<", "<", $read); |
| 79 | $read = ereg_replace(">", ">", $read); |
| 80 | $subject[$pos] = substr($read, 8, strlen($read) - 9); |
| 81 | if (strlen(Chop($subject[$pos])) == 0) |
| 82 | $subject[$pos] = "(no subject)"; |
| 83 | } |
| 84 | else if (substr($read, 0, 1) == ")") { |
| 85 | if ($subject[$pos] == "") |
| 86 | $subject[$pos] = "(no subject)"; |
| 87 | else if ($from[$pos] == "") |
| 88 | $from[$pos] = "(unknown sender)"; |
| 89 | else if ($date[$pos] == "") |
| 90 | $from[$pos] = gettimeofday(); |
| 91 | |
| 92 | $pos++; |
| 93 | } |
| 94 | |
| 95 | $read = fgets($imapConnection, 1024); |
| 96 | } |
| 97 | $rel_start = $rel_start + 50; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | function encodeEmailAddr($string) { |
| 102 | $string = ereg_replace("<", "EMAILSTART--", $string); |
| 103 | $string = ereg_replace(">", "--EMAILEND", $string); |
| 104 | return $string; |
| 105 | } |
| 106 | |
| 107 | function setMessageFlag($imapConnection, $i, $q, $flag) { |
| 108 | fputs($imapConnection, "messageStore STORE $i:$q +FLAGS (\\$flag)\n"); |
| 109 | } |
| 110 | |
| 111 | /** This function gets the flags for message $j. It does only one message at a |
| 112 | ** time, rather than doing groups of messages (like getMessageHeaders does). |
| 113 | ** I found it one or two seconds quicker (on a box of 800 messages) to do it |
| 114 | ** individually. I'm not sure why it happens like that, but that's what my |
| 115 | ** testing found. Perhaps later I will be proven wrong and this will change. |
| 116 | **/ |
| 117 | function getMessageFlags($imapConnection, $low, $high, &$flags) { |
| 118 | /** * 2 FETCH (FLAGS (\Answered \Seen)) */ |
| 119 | fputs($imapConnection, "messageFetch FETCH $low:$high FLAGS\n"); |
| 120 | $read = fgets($imapConnection, 1024); |
| 121 | $count = 0; |
| 122 | while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) { |
| 123 | if (strpos($read, "FLAGS")) { |
| 124 | $read = ereg_replace("\(", "", $read); |
| 125 | $read = ereg_replace("\)", "", $read); |
| 126 | $read = str_replace("\\", "", $read); |
| 127 | $read = substr($read, strpos($read, "FLAGS")+6, strlen($read)); |
| 128 | $read = trim($read); |
| 129 | $flags[$count] = explode(" ", $read);; |
| 130 | } else { |
| 131 | $flags[$count][0] = "None"; |
| 132 | } |
| 133 | $count++; |
| 134 | $read = fgets($imapConnection, 1024); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | function decodeEmailAddr($sender) { |
| 139 | $emailAddr = getEmailAddr($sender); |
| 140 | if (strpos($emailAddr, "EMAILSTART--")) { |
| 141 | |
| 142 | $emailAddr = ereg_replace("EMAILSTART--", "", $emailAddr); |
| 143 | $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr); |
| 144 | } else { |
| 145 | $emailAddr = $emailAddr; |
| 146 | } |
| 147 | return $emailAddr; |
| 148 | } |
| 149 | |
| 150 | function getEmailAddr($sender) { |
| 151 | if (strpos($sender, "EMAILSTART--") == false) |
| 152 | return "$sender"; |
| 153 | |
| 154 | $emailStart = strpos($sender, "EMAILSTART--") + 12; |
| 155 | $emailAddr = substr($sender, $emailStart, strlen($sender)); |
| 156 | $emailAddr = substr($emailAddr, 0, strpos($emailAddr, "--EMAILEND")); |
| 157 | |
| 158 | return $emailAddr; |
| 159 | } |
| 160 | |
| 161 | function getSender($sender) { |
| 162 | if (strpos($sender, "EMAILSTART--") == false) |
| 163 | return "$sender"; |
| 164 | |
| 165 | $first = substr($sender, 0, strpos($sender, "EMAILSTART--")); |
| 166 | $second = substr($sender, strpos($sender, "--EMAILEND") +10, strlen($sender)); |
| 167 | return "$first $second"; |
| 168 | } |
| 169 | |
| 170 | function getSenderName($sender) { |
| 171 | $name = getSender($sender); |
| 172 | $emailAddr = getEmailAddr($sender); |
| 173 | $emailStart = strpos($emailAddr, "EMAILSTART--"); |
| 174 | $emailEnd = strpos($emailAddr, "--EMAILEND") - 10; |
| 175 | |
| 176 | if (($emailAddr == "") && ($name == "")) { |
| 177 | $from = $sender; |
| 178 | } |
| 179 | else if ((strstr($name, "?") != false) || (strstr($name, "$") != false) || (strstr($name, "%") != false)){ |
| 180 | $emailAddr = ereg_replace("EMAILSTART--", "", $emailAddr); |
| 181 | $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr); |
| 182 | $from = $emailAddr; |
| 183 | } |
| 184 | else if (strlen($name) > 0) { |
| 185 | $from = $name; |
| 186 | } |
| 187 | else if (strlen($emailAddr > 0)) { |
| 188 | $emailAddr = ereg_replace("EMAILSTART--", "", $emailAddr); |
| 189 | $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr); |
| 190 | $from = $emailAddr; |
| 191 | } |
| 192 | |
| 193 | $from = trim($from); |
| 194 | |
| 195 | // strip out any quotes if they exist |
| 196 | if ((strlen($from) > 0) && ($from[0] == "\"") && ($from[strlen($from) - 1] == "\"")) |
| 197 | $from = substr($from, 1, strlen($from) - 2); |
| 198 | |
| 199 | return $from; |
| 200 | } |
| 201 | |
| 202 | /** returns "true" if the copy was completed successfully. |
| 203 | ** returns "false" with an error message if unsuccessful. |
| 204 | **/ |
| 205 | function copyMessages($imapConnection, $from_id, $to_id, $folder) { |
| 206 | fputs($imapConnection, "mailboxStore COPY $from_id:$to_id \"$folder\"\n"); |
| 207 | $read = fgets($imapConnection, 1024); |
| 208 | while ((substr($read, 0, 15) != "mailboxStore OK") && (substr($read, 0, 15) != "mailboxStore NO")) { |
| 209 | $read = fgets($imapConnection, 1024); |
| 210 | } |
| 211 | |
| 212 | if (substr($read, 0, 15) == "mailboxStore NO") { |
| 213 | return false; |
| 214 | } else if (substr($read, 0, 15) == "mailboxStore OK") { |
| 215 | return true; |
| 216 | } |
| 217 | |
| 218 | echo "UNKNOWN ERROR copying messages $from_id to $to_id to folder $folder.<BR>"; |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | /** expunges a mailbox **/ |
| 223 | function expungeBox($imapConnection, $mailbox) { |
| 224 | selectMailbox($imapConnection, $mailbox, $num); |
| 225 | fputs($imapConnection, "1 EXPUNGE\n"); |
| 226 | imapReadData($imapConnection, "1", true, $response, $message); |
| 227 | } |
| 228 | |
| 229 | function getFolderNameMinusINBOX($mailbox, $del) { |
| 230 | $inbox = "INBOX" . $del; |
| 231 | if (substr($mailbox, 0, strlen($inbox)) == $inbox) |
| 232 | $box = substr($mailbox, strlen($inbox), strlen($mailbox)); |
| 233 | else |
| 234 | $box = $mailbox; |
| 235 | |
| 236 | return $box; |
| 237 | } |
| 238 | |
| 239 | /** This function gets all the information about a message. Including Header and body **/ |
| 240 | function fetchMessage($imapConnection, $id, $mailbox) { |
| 241 | $message["INFO"]["ID"] = $id; |
| 242 | $message["INFO"]["MAILBOX"] = $mailbox; |
| 243 | $message["HEADER"] = fetchHeader($imapConnection, $id); |
| 244 | $message["ENTITIES"] = fetchBody($imapConnection, $message["HEADER"]["BOUNDARY"], $id, $message["HEADER"]["TYPE0"], $message["HEADER"]["TYPE1"]); |
| 245 | return $message; |
| 246 | } |
| 247 | |
| 248 | function fetchHeader($imapConnection, $id) { |
| 249 | fputs($imapConnection, "messageFetch FETCH $id:$id RFC822.HEADER\n"); |
| 250 | $read = fgets($imapConnection, 1024); |
| 251 | |
| 252 | /** defaults... if the don't get overwritten, it will display text **/ |
| 253 | $header["TYPE0"] = "text"; |
| 254 | $header["TYPE1"] = "plain"; |
| 255 | $header["ENCODING"] = "us-ascii"; |
| 256 | while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) { |
| 257 | /** MIME-VERSION **/ |
| 258 | if (substr($read, 0, 17) == "MIME-Version: 1.0") { |
| 259 | $header["MIME"] = true; |
| 260 | $read = fgets($imapConnection, 1024); |
| 261 | } |
| 262 | |
| 263 | /** ENCODING TYPE **/ |
| 264 | else if (substr(strtolower($read[$i]), 0, 26) == "content-transfer-encoding:") { |
| 265 | $header["ENCODING"] = strtolower(trim(substr($read[$i], 26))); |
| 266 | } |
| 267 | |
| 268 | /** CONTENT-TYPE **/ |
| 269 | else if (substr($read, 0, 13) == "Content-Type:") { |
| 270 | $cont = strtolower(trim(substr($read, 13))); |
| 271 | if (strpos($cont, ";")) |
| 272 | $cont = substr($cont, 0, strpos($cont, ";")); |
| 273 | |
| 274 | if (strpos($cont, "/")) { |
| 275 | $header["TYPE0"] = substr($cont, 0, strpos($cont, "/")); |
| 276 | $header["TYPE1"] = substr($cont, strpos($cont, "/")+1); |
| 277 | } else { |
| 278 | $header["TYPE0"] = $cont; |
| 279 | } |
| 280 | |
| 281 | $line = $read; |
| 282 | $read = fgets($imapConnection, 1024); |
| 283 | while ( (substr(substr($read, 0, strpos($read, " ")), -1) != ":") && (trim($read) != "") && (trim($read) != ")")) { |
| 284 | str_replace("\n", "", $line); |
| 285 | str_replace("\n", "", $read); |
| 286 | $line = "$line $read"; |
| 287 | $read = fgets($imapConnection, 1024); |
| 288 | } |
| 289 | |
| 290 | /** Detect the boundary of a multipart message **/ |
| 291 | if (strpos(strtolower(trim($line)), "boundary=")) { |
| 292 | $pos = strpos($line, "boundary=") + 9; |
| 293 | $bound = trim($line); |
| 294 | if (strpos($line, " ", $pos) > 0) { |
| 295 | $bound = substr($bound, $pos, strpos($line, " ", $pos)); |
| 296 | } else { |
| 297 | $bound = substr($bound, $pos); |
| 298 | } |
| 299 | $bound = str_replace("\"", "", $bound); |
| 300 | $header["BOUNDARY"] = $bound; |
| 301 | } |
| 302 | |
| 303 | /** Detect the charset **/ |
| 304 | if (strpos(strtolower(trim($line)), "charset=")) { |
| 305 | $pos = strpos($line, "charset=") + 8; |
| 306 | $charset = trim($line); |
| 307 | if (strpos($line, " ", $pos) > 0) { |
| 308 | $charset = substr($charset, $pos, strpos($line, " ", $pos)); |
| 309 | } else { |
| 310 | $charset = substr($charset, $pos); |
| 311 | } |
| 312 | $charset = str_replace("\"", "", $charset); |
| 313 | $header["CHARSET"] = $charset; |
| 314 | } else { |
| 315 | $header["CHARSET"] = "us-ascii"; |
| 316 | } |
| 317 | |
| 318 | /** Detects filename if any **/ |
| 319 | if (strpos(strtolower(trim($line)), "name=")) { |
| 320 | $pos = strpos($line, "name=") + 5; |
| 321 | $name = trim($line); |
| 322 | if (strpos($line, " ", $pos) > 0) { |
| 323 | $name = substr($name, $pos, strpos($line, " ", $pos)); |
| 324 | } else { |
| 325 | $name = substr($name, $pos); |
| 326 | } |
| 327 | $name = str_replace("\"", "", $name); |
| 328 | $header["FILENAME"] = $name; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /** REPLY-TO **/ |
| 333 | else if (strtolower(substr($read, 0, 9)) == "reply-to:") { |
| 334 | $header["REPLYTO"] = trim(substr($read, 9, strlen($read))); |
| 335 | $read = fgets($imapConnection, 1024); |
| 336 | } |
| 337 | |
| 338 | /** FROM **/ |
| 339 | else if (strtolower(substr($read, 0, 5)) == "from:") { |
| 340 | $header["FROM"] = trim(substr($read, 5, strlen($read) - 6)); |
| 341 | if ($header["REPLYTO"] == "") |
| 342 | $header["REPLYTO"] = $header["FROM"]; |
| 343 | $read = fgets($imapConnection, 1024); |
| 344 | } |
| 345 | /** DATE **/ |
| 346 | else if (strtolower(substr($read, 0, 5)) == "date:") { |
| 347 | $d = substr($read, 5, strlen($read) - 6); |
| 348 | $d = trim($d); |
| 349 | $d = ereg_replace(" ", " ", $d); |
| 350 | $d = explode(" ", $d); |
| 351 | $header["DATE"] = getTimeStamp($d); |
| 352 | $read = fgets($imapConnection, 1024); |
| 353 | } |
| 354 | /** SUBJECT **/ |
| 355 | else if (strtolower(substr($read, 0, 8)) == "subject:") { |
| 356 | $header["SUBJECT"] = trim(substr($read, 8, strlen($read) - 9)); |
| 357 | if (strlen(Chop($header["SUBJECT"])) == 0) |
| 358 | $header["SUBJECT"] = "(no subject)"; |
| 359 | $read = fgets($imapConnection, 1024); |
| 360 | } |
| 361 | /** CC **/ |
| 362 | else if (strtolower(substr($read, 0, 3)) == "cc:") { |
| 363 | $pos = 0; |
| 364 | $header["CC"][$pos] = trim(substr($read, 4)); |
| 365 | $read = fgets($imapConnection, 1024); |
| 366 | while ((substr($read, 0, 1) == " ") && (trim($read) != "")) { |
| 367 | $pos++; |
| 368 | $header["CC"][$pos] = trim($read); |
| 369 | $read = fgets($imapConnection, 1024); |
| 370 | } |
| 371 | } |
| 372 | /** TO **/ |
| 373 | else if (strtolower(substr($read, 0, 3)) == "to:") { |
| 374 | $pos = 0; |
| 375 | $header["TO"][$pos] = trim(substr($read, 4)); |
| 376 | $read = fgets($imapConnection, 1024); |
| 377 | while ((substr($read, 0, 1) == " ") && (trim($read) != "")){ |
| 378 | $pos++; |
| 379 | $header["TO"][$pos] = trim($read); |
| 380 | $read = fgets($imapConnection, 1024); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /** ERROR CORRECTION **/ |
| 385 | else if (substr($read, 0, 1) == ")") { |
| 386 | if ($header["SUBJECT"] == "") |
| 387 | $header["SUBJECT"] = "(no subject)"; |
| 388 | |
| 389 | if ($header["FROM"] == "") |
| 390 | $header["FROM"] = "(unknown sender)"; |
| 391 | |
| 392 | if ($header["DATE"] == "") |
| 393 | $header["DATE"] = time(); |
| 394 | $read = fgets($imapConnection, 1024); |
| 395 | } |
| 396 | else { |
| 397 | $read = fgets($imapConnection, 1024); |
| 398 | } |
| 399 | } |
| 400 | return $header; |
| 401 | } |
| 402 | |
| 403 | function fetchBody($imapConnection, $bound, $id, $type0, $type1) { |
| 404 | /** This first part reads in the full body of the message **/ |
| 405 | fputs($imapConnection, "messageFetch FETCH $id:$id BODY[TEXT]\n"); |
| 406 | $read = fgets($imapConnection, 1024); |
| 407 | |
| 408 | $count = 0; |
| 409 | while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) { |
| 410 | $body[$count] = $read; |
| 411 | $count++; |
| 412 | |
| 413 | $read = fgets($imapConnection, 1024); |
| 414 | } |
| 415 | |
| 416 | /** this deletes the first line, and the last two (imap stuff we ignore) **/ |
| 417 | $i = 0; |
| 418 | $j = 0; |
| 419 | while ($i < count($body)) { |
| 420 | if ( ($i != 0) && ($i != count($body) - 1) && ($i != count($body)) ) { |
| 421 | $bodytmp[$j] = $body[$i]; |
| 422 | $j++; |
| 423 | } |
| 424 | $i++; |
| 425 | } |
| 426 | $body = $bodytmp; |
| 427 | |
| 428 | /** Now, lets work out the MIME stuff **/ |
| 429 | /** (needs mime.php included) **/ |
| 430 | return decodeMime($body, $bound, $type0, $type1); |
| 431 | } |
| 432 | |
| 433 | function fetchEntityHeader($imapConnection, &$read, &$type0, &$type1, &$bound, &$encoding, &$charset, &$filename) { |
| 434 | /** defaults... if the don't get overwritten, it will display text **/ |
| 435 | $type0 = "text"; |
| 436 | $type1 = "plain"; |
| 437 | $encoding = "us-ascii"; |
| 438 | $i = 0; |
| 439 | while (trim($read[$i]) != "") { |
| 440 | if (substr(strtolower($read[$i]), 0, 26) == "content-transfer-encoding:") { |
| 441 | $encoding = strtolower(trim(substr($read[$i], 26))); |
| 442 | |
| 443 | } else if (substr($read[$i], 0, 13) == "Content-Type:") { |
| 444 | $cont = strtolower(trim(substr($read[$i], 13))); |
| 445 | if (strpos($cont, ";")) |
| 446 | $cont = substr($cont, 0, strpos($cont, ";")); |
| 447 | |
| 448 | if (strpos($cont, "/")) { |
| 449 | $type0 = substr($cont, 0, strpos($cont, "/")); |
| 450 | $type1 = substr($cont, strpos($cont, "/")+1); |
| 451 | } else { |
| 452 | $type0 = $cont; |
| 453 | } |
| 454 | |
| 455 | $read[$i] = trim($read[$i]); |
| 456 | $line = $read[$i]; |
| 457 | $i++; |
| 458 | while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) { |
| 459 | str_replace("\n", "", $line); |
| 460 | str_replace("\n", "", $read[$i]); |
| 461 | $line = "$line $read[$i]"; |
| 462 | $i++; |
| 463 | $read[$i] = trim($read[$i]); |
| 464 | } |
| 465 | $i--; |
| 466 | |
| 467 | /** Detect the boundary of a multipart message **/ |
| 468 | if (strpos(strtolower(trim($line)), "boundary=")) { |
| 469 | $pos = strpos($line, "boundary=") + 9; |
| 470 | $bound = trim($line); |
| 471 | if (strpos($line, " ", $pos) > 0) { |
| 472 | $bound = substr($bound, $pos, strpos($line, " ", $pos)); |
| 473 | } else { |
| 474 | $bound = substr($bound, $pos); |
| 475 | } |
| 476 | $bound = str_replace("\"", "", $bound); |
| 477 | } |
| 478 | |
| 479 | /** Detect the charset **/ |
| 480 | if (strpos(strtolower(trim($line)), "charset=")) { |
| 481 | $pos = strpos($line, "charset=") + 8; |
| 482 | $charset = trim($line); |
| 483 | if (strpos($line, " ", $pos) > 0) { |
| 484 | $charset = substr($charset, $pos, strpos($line, " ", $pos)); |
| 485 | } else { |
| 486 | $charset = substr($charset, $pos); |
| 487 | } |
| 488 | $charset = str_replace("\"", "", $charset); |
| 489 | } |
| 490 | |
| 491 | /** Detects filename if any **/ |
| 492 | if (strpos(strtolower(trim($line)), "name=")) { |
| 493 | $pos = strpos($line, "name=") + 5; |
| 494 | $name = trim($line); |
| 495 | if (strpos($line, " ", $pos) > 0) { |
| 496 | $name = substr($name, $pos, strpos($line, " ", $pos)); |
| 497 | } else { |
| 498 | $name = substr($name, $pos); |
| 499 | } |
| 500 | $name = str_replace("\"", "", $name); |
| 501 | $filename = $name; |
| 502 | } |
| 503 | } |
| 504 | $i++; |
| 505 | } |
| 506 | |
| 507 | /** remove the header from the entity **/ |
| 508 | $i = 0; |
| 509 | while (trim($read[$i]) != "") { |
| 510 | $i++; |
| 511 | } |
| 512 | $i++; |
| 513 | |
| 514 | for ($p = 0; $i < count($read); $p++) { |
| 515 | $entity[$p] = $read[$i]; |
| 516 | $i++; |
| 517 | } |
| 518 | |
| 519 | $read = $entity; |
| 520 | } |
| 521 | |
| 522 | ?> |