/read_full_email_from_db.php

https://github.com/suhastech/pushmail · PHP · 160 lines · 102 code · 36 blank · 22 comment · 13 complexity · 10148ca19110657f7fc071eff7b5000a MD5 · raw file

  1. <?php
  2. include ('common.php');
  3. ?>
  4. <html>
  5. <head>
  6. <meta name="txtweb-appkey" content="<?php echo $txtwebappkey; ?>" />
  7. </head>
  8. <body>
  9. <?php
  10. function callback($buffer)
  11. {
  12. // Replace the next line character "\n" with "<br />". The txtweb parses pages as HTML. So, this is needed.
  13. return (str_replace("\n", "<br />", $buffer));
  14. }
  15. ob_start("callback");
  16. if(isset($_GET['id']))
  17. {
  18. // mysql connect
  19. mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error());
  20. mysql_select_db($dbname) or die(mysql_error());
  21. $id = $_GET['id'];
  22. $result = mysql_query("SELECT * FROM db WHERE id='$id'");
  23. // If the required email exists in the table
  24. if (mysql_num_rows($result) > 0)
  25. {
  26. // Gives a "To reply to this email" intent.
  27. echo "To reply to this message: <br />";
  28. ?>
  29. <form class="txtweb-form" action="<?php echo $scriptpath; ?>reply_to_email.php?id=<?php echo $id;?>" method="GET">
  30. your-reply-message<input name="reply" type="text" />
  31. <input type="submit" value="Submit" />
  32. </form>
  33. <?php
  34. $row=mysql_fetch_array($result);
  35. $mobile = $_GET['txtweb-mobile'];
  36. // fetch the Unique identifier to decrypt
  37. $togetui = mysql_query("SELECT * FROM users WHERE mobile='$mobile'");
  38. $arraytable=mysql_fetch_array($togetui);
  39. // Decrypts the email with the Unique Identifier as the key.
  40. $email = mysql_aes_decrypt($row['body'],intval($arraytable['ui'] ));
  41. require_once('class/rfc822_addresses.php');
  42. require_once('class/mime_parser.php');
  43. //create the email parser class
  44. $mime=new mime_parser_class;
  45. $mime->ignore_syntax_errors = 1;
  46. $parameters=array(
  47. 'Data'=>$email,
  48. );
  49. $mime->Decode($parameters, $decoded);
  50. //get the name and email of the sender
  51. $fromName = $decoded[0]['ExtractedAddresses']['from:'][0]['name'];
  52. $fromEmail = $decoded[0]['ExtractedAddresses']['from:'][0]['address'];
  53. //get the name and email of the recipient
  54. $toEmail = $decoded[0]['ExtractedAddresses']['to:'][0]['address'];
  55. $toName = $decoded[0]['ExtractedAddresses']['to:'][0]['name'];
  56. //get the subject
  57. $subject = $decoded[0]['Headers']['subject:'];
  58. $removeChars = array('<','>');
  59. //get the message body
  60. if(substr($decoded[0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Body'])){
  61. $body = $decoded[0]['Body'];
  62. } elseif(substr($decoded[0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Body'])) {
  63. $body = $decoded[0]['Parts'][0]['Body'];
  64. } elseif(substr($decoded[0]['Parts'][0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Parts'][0]['Body'])) {
  65. $body = $decoded[0]['Parts'][0]['Parts'][0]['Body'];
  66. }
  67. if (isset($body))
  68. {
  69. //get rid of any quoted text in the email body
  70. $body_array = explode("\n",$body);
  71. $message = "";
  72. foreach($body_array as $key => $value){
  73. //remove hotmail sig
  74. if($value == "_________________________________________________________________"){
  75. break;
  76. //original message quote
  77. } elseif(preg_match("/^-*(.*)Original Message(.*)-*/i",$value,$matches)){
  78. break;
  79. //check for date wrote string
  80. } elseif(preg_match("/^On(.*)wrote:(.*)/i",$value,$matches)) {
  81. break;
  82. //check for From Name email section
  83. } elseif(preg_match("/^On(.*)$fromName(.*)/i",$value,$matches)) {
  84. break;
  85. //check for To Name email section
  86. } elseif(preg_match("/^On(.*)$toName(.*)/i",$value,$matches)) {
  87. break;
  88. //check for To Email email section
  89. } elseif(preg_match("/^(.*)$toEmail(.*)wrote:(.*)/i",$value,$matches)) {
  90. break;
  91. //check for From Email email section
  92. } elseif(preg_match("/^(.*)$fromEmail(.*)wrote:(.*)/i",$value,$matches)) {
  93. break;
  94. //check for quoted ">" section
  95. } elseif(preg_match("/^>(.*)/i",$value,$matches)){
  96. break;
  97. //check for date wrote string with dashes
  98. } elseif(preg_match("/^---(.*)On(.*)wrote:(.*)/i",$value,$matches)){
  99. break;
  100. //add line to body
  101. } else {
  102. $message .= "$value\n";
  103. }
  104. }
  105. echo "$message";
  106. }
  107. else
  108. {
  109. echo "Sorry, no plain text part, here.";
  110. }
  111. }
  112. else
  113. {
  114. echo "Sorry, email couldn't be found. Emails will be pruned after 24 hours from our database.";
  115. }
  116. }
  117. ob_end_flush();
  118. ?>
  119. </body>
  120. </html>