PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/classes/mail.php

http://rapidleech36b.googlecode.com/
PHP | 133 lines | 121 code | 12 blank | 0 comment | 36 complexity | e5be4e61e8619b4a600fc49d83f6ca81 MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require ('../404.php');
  4. exit();
  5. }
  6. function xmail($from, $to, $subj, $text, $filename, $partSize = FALSE, $method = FALSE) {
  7. global $un, $L;
  8. $fileContents = read_file($filename);
  9. $fileSize = strlen($fileContents);
  10. if ($partSize != FALSE & $method == "tc") {
  11. $crc = strtoupper(dechex(crc32($fileContents)));
  12. $crc = str_repeat("0", 8 - strlen($crc)) . $crc;
  13. } else {
  14. $file = base64_encode($fileContents);
  15. $file = chunk_split($file);
  16. unset($fileContents);
  17. }
  18. if (!$file && !$fileContents) {
  19. return FALSE;
  20. }
  21. $L->sprintf($L->say['_sendfile'], basename($filename));
  22. echo "...<br />";
  23. flush();
  24. sleep(1);
  25. for ($i = 0; $i < strlen($subj); $i++) {
  26. $subzh .= "=" . strtoupper(dechex(ord(substr($subj, $i, 1))));
  27. }
  28. $subj = "=?UTF-8?Q?" . $subzh . '?=';
  29. $un = strtoupper(uniqid(time()));
  30. $head = "From: " . $from . "\n" . "X-Mailer: PHP RapidLeech 36B\n" . "Reply-To: " . $from . "\n" . "Mime-Version: 1.0\n" . "Content-Type: multipart/mixed; boundary=\"----------" . $un . "\"\n\n";
  31. $zag = "------------" . $un . "\nContent-Type: text/plain; charset=UTF-8\n" . "Content-Transfer-Encoding: 8bit\n\n" . $text . "\n\n" . "------------" . $un . "\n" . "Content-Type: application/octet-stream; name=\"" . basename($filename) . "\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment; filename=\"" . basename($filename) . "\"\n\n";
  32. echo '<span id="mailPart.' . md5(basename($filename)) . '"></span><br />';
  33. flush();
  34. if ($partSize) {
  35. $partSize = round($partSize);
  36. if ($method == "rfc") {
  37. $multiHeadMain = "From: " . $from . "\n" . "X-Mailer: PHP RapidLeech 36B\n" . "Reply-To: " . $from . "\n" . "Mime-Version: 1.0\n" . "Content-Type: message/partial; ";
  38. $totalParts = ceil(strlen($file) / $partSize);
  39. if ($totalParts == 1) {
  40. echo $L->say['_nosplitemail'] . "...<br />";
  41. flush();
  42. return mail($to, $subj, $zag . $file, $head) ? TRUE : FALSE;
  43. }
  44. $L->sprintf($L->say['_splitpart'], bytesToKbOrMbOrGb($partSize));
  45. echo ", " . $L->say['_method'] . " - RFC 2046...<br />";
  46. echo "Total Parts: <b>" . $totalParts . "</b><br />";
  47. $mailed = TRUE;
  48. echo('<script type="text/javascript">');
  49. for ($i = 0; $i < $totalParts; $i++) {
  50. $multiHead = $multiHeadMain . "id=\"" . $filename . "\"; number=" . ($i + 1) . "; total=" . $totalParts . "\n\n";
  51. if ($i == 0) {
  52. $multiHead = $multiHead . $head;
  53. $fileChunk = $zag . substr($file, 0, $partSize);
  54. } elseif ($i == $totalParts - 1) {
  55. $fileChunk = substr($file, $i * $partSize);
  56. } else {
  57. $fileChunk = substr($file, $i * $partSize, $partSize);
  58. }
  59. echo "mail('" . $L->sprintf($L->say['_sendpart'], ($i + 1)) . "...', '" . md5(basename($filename)) . "');\r\n";
  60. flush();
  61. $mailed = $mailed & mail($to, $subj, $fileChunk, $multiHead);
  62. if (!$mailed) {
  63. return false;
  64. }
  65. }
  66. echo('</script>');
  67. } elseif ($method == "tc") {
  68. $totalParts = ceil($fileSize / $partSize);
  69. if ($totalParts == 1) {
  70. echo $L->say['_nosplitemail'] . "...<br />";
  71. flush();
  72. return mail($to, $subj, $zag . chunk_split(base64_encode($fileContents)), $head) ? TRUE : FALSE;
  73. }
  74. $L->sprintf($L->say['_splitpart'], bytesToKbOrMbOrGb($partSize));
  75. echo ", " . $L->say['_method'] . " - Total Commander...<br />";
  76. echo "Total Parts: <b>" . $totalParts . "</b><br />";
  77. $mailed = TRUE;
  78. $fileTmp = $filename;
  79. while (strpos($fileTmp, ".")) {
  80. $fileName .= substr($fileTmp, 0, strpos($fileTmp, ".") + 1);
  81. $fileTmp = substr($fileTmp, strpos($fileTmp, ".") + 1);
  82. }
  83. $fileName = substr($fileName, 0, - 1);
  84. echo('<script type="text/javascript">');
  85. for ($i = 0; $i < $totalParts; $i++) {
  86. if ($i == 0) {
  87. $fileChunk = substr($fileContents, 0, $partSize);
  88. $addHeads = addAdditionalHeaders(array("msg" => $text . "\r\n" . "File " . basename($filename) . " (????? " . ($i + 1) . " ?? " . $totalParts . ").", "file" => array("filename" => $fileName . ".crc", "stream" => chunk_split(base64_encode("filename=" . basename($filename) . "\r\n" . "size=" . $fileSize . "\r\n" . "crc32=" . $crc . "\r\n")))));
  89. $addHeads .= addAdditionalHeaders(array("file" => array("filename" => $fileName . ".001", "stream" => chunk_split(base64_encode($fileChunk)))));
  90. } elseif ($i == $totalParts - 1) {
  91. $fileChunk = substr($fileContents, $i * $partSize);
  92. $addHeads = addAdditionalHeaders(array("msg" => "File " . basename($filename) . " (parts " . ($i + 1) . " from " . $totalParts . ").", "file" => array("filename" => $fileName . "." . (strlen($i + 1) == 2 ? "0" . ($i + 1) : (strlen($i + 1) == 1 ? "00" . ($i + 1) : ($i + 1))), "stream" => chunk_split(base64_encode($fileChunk)))));
  93. } else {
  94. $fileChunk = substr($fileContents, $i * $partSize, $partSize);
  95. $addHeads = addAdditionalHeaders(array("msg" => "File " . basename($filename) . " (parts " . ($i + 1) . " from " . $totalParts . ").", "file" => array("filename" => $fileName . "." . (strlen($i + 1) == 2 ? "0" . ($i + 1) : (strlen($i + 1) == 1 ? "00" . ($i + 1) : ($i + 1))), "stream" => chunk_split(base64_encode($fileChunk)))));
  96. }
  97. echo "mail('" . $L->sprintf($L->say['_sendpart'], ($i + 1)) . "...', '" . md5(basename($filename)) . "');\r\n";
  98. flush();
  99. $mailed = $mailed & mail($to, $subj, $addHeads, $head);
  100. if (!$mailed) {
  101. return false;
  102. }
  103. }
  104. echo('</script>');
  105. }
  106. } else {
  107. return mail($to, $subj, $zag . $file, $head) ? TRUE : FALSE;
  108. }
  109. return $mailed ? TRUE : FALSE;
  110. }
  111. function addAdditionalHeaders($head) {
  112. global $un;
  113. if ($head ["msg"]) {
  114. $ret = "------------" . $un . "\nContent-Type: text/plain; charset=UTF-8\n" . "Content-Transfer-Encoding: 8bit\n\n" . $head ["msg"] . "\n\n";
  115. }
  116. if ($head ["file"] ["filename"]) {
  117. $ret .= "------------" . $un . "\n" . "Content-Type: application/octet-stream; name=\"" . basename($head ["file"] ["filename"]) . "\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment; filename=\"" . basename($head ["file"] ["filename"]) . "\"\n\n" . $head ["file"] ["stream"] . "\n\n";
  118. }
  119. return $ret;
  120. }
  121. ?>