mailbox.php 22 KB

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