setup.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. require_once('../functions/url_parser.php');
  3. /* Address Take -- steals addresses from incoming email messages. Searches
  4. the To, Cc, From and Reply-To headers, also searches the body of the
  5. message. */
  6. function squirrelmail_plugin_init_abook_take()
  7. {
  8. global $squirrelmail_plugin_hooks;
  9. $squirrelmail_plugin_hooks['read_body_bottom']['abook_take'] = 'abook_take_read';
  10. $squirrelmail_plugin_hooks['loading_prefs']['abook_take'] = 'abook_take_pref';
  11. $squirrelmail_plugin_hooks['options_display_inside']['abook_take'] = 'abook_take_options';
  12. $squirrelmail_plugin_hooks['options_display_save']['abook_take'] = 'abook_take_save';
  13. }
  14. function valid_email ($email, $verify)
  15. {
  16. global $abook_take_verify, $Email_RegExp_Match;
  17. if (! eregi('^' . $Email_RegExp_Match . '$', $email))
  18. return false;
  19. if (! $verify)
  20. return true;
  21. if (! checkdnsrr(substr(strstr($email, '@'), 1), 'ANY'))
  22. return false;
  23. return true;
  24. }
  25. function abook_take_read_string($str)
  26. {
  27. global $abook_found_email, $Email_RegExp_Match;
  28. while (eregi('(' . $Email_RegExp_Match . ')', $str, $hits))
  29. {
  30. $str = substr(strstr($str, $hits[0]), strlen($hits[0]));
  31. if (! isset($abook_found_email[$hits[0]]))
  32. {
  33. echo "<input type=\"hidden\" name=\"email[]\" value=\"$hits[0]\">\n";
  34. $abook_found_email[$hits[0]] = 1;
  35. }
  36. }
  37. return;
  38. }
  39. function abook_take_read_array($array)
  40. {
  41. $i = 0;
  42. while ($i < count($array))
  43. {
  44. abook_take_read_string($array[$i]);
  45. $i ++;
  46. }
  47. }
  48. function abook_take_read()
  49. {
  50. global $color, $abook_take_location;
  51. global $body, $abook_take_hide, $message, $imapConnection;
  52. if ($abook_take_hide)
  53. return;
  54. echo '<form action="../plugins/abook_take/take.php" method="post">' . "\n" .
  55. html_tag( 'table', '', $abook_take_location, $color[10], 'cellpadding="3" cellspacing="0" border="0"' ) .
  56. html_tag( 'tr' ) .
  57. html_tag( 'td', '', 'left' ) .
  58. html_tag( 'table', '', '', $color[5], 'cellpadding="2" cellspacing="1" border="0"' ) .
  59. html_tag( 'tr' ) .
  60. html_tag( 'td' );
  61. abook_take_read_string($message->header->from);
  62. abook_take_read_array($message->header->cc);
  63. abook_take_read_array($message->header->reply_to);
  64. abook_take_read_array($message->header->to);
  65. $new_body = $body;
  66. $pos = strpos($new_body,
  67. '">' . _("Download this as a file") . '</a></center><br></small>');
  68. if (is_int($pos))
  69. {
  70. $new_body = substr($new_body, 0, $pos);
  71. }
  72. $trans = get_html_translation_table(HTML_ENTITIES);
  73. $trans[' '] = '&nbsp;';
  74. $trans = array_flip($trans);
  75. $new_body = strtr($new_body, $trans);
  76. $new_body = urldecode($new_body);
  77. $new_body = strip_tags($new_body);
  78. $new_body = strtr($new_body, "\n", ' ');
  79. abook_take_read_string($body);
  80. echo '<input type="submit" value="' . _("Take Address") . '">';
  81. ?>
  82. </td>
  83. </tr>
  84. </table>
  85. </td>
  86. </tr>
  87. </table>
  88. </form>
  89. <?PHP
  90. }
  91. function abook_take_pref()
  92. {
  93. global $username, $data_dir;
  94. global $abook_take_hide, $abook_take_location, $abook_take_verify;
  95. $abook_take_location = getPref($data_dir, $username, 'abook_take_location');
  96. if ($abook_take_location == '')
  97. $abook_take_location = 'center';
  98. $abook_take_hide = getPref($data_dir, $username, 'abook_take_hide');
  99. $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify');
  100. }
  101. function abook_take_options()
  102. {
  103. global $abook_take_location, $abook_take_hide, $abook_take_verify;
  104. echo html_tag( 'tr' ) .
  105. html_tag( 'td', _("Address Book Take") . ':', 'right', '', 'nowrap valign="top"' ) .
  106. html_tag( 'td', '', 'left' ) .
  107. '<select name="abook_take_abook_take_location">' .
  108. '<option value="left"';
  109. if ($abook_take_location == 'left')
  110. echo ' selected';
  111. echo '>' . _("Left aligned") . '</option>' .
  112. '<option value="center"';
  113. if ($abook_take_location == 'center')
  114. echo ' selected';
  115. echo '>' . _("Centered") . '</option>' .
  116. '<option value="right"';
  117. if ($abook_take_location == 'right')
  118. echo ' selected';
  119. echo '>' . _("Right aligned") . '</option>' .
  120. '</select> ' . _("on the Read screen") .'<br>' .
  121. '<input type="checkbox" name="abook_take_abook_take_hide"';
  122. if ($abook_take_hide)
  123. echo ' checked';
  124. echo '>&nbsp;' . _("Hide the box") . '<br>' .
  125. '<input type=checkbox name="abook_take_abook_take_verify"';
  126. if ($abook_take_verify)
  127. echo ' checked';
  128. echo '>&nbsp;' . _("Try to verify addresses") . '</td></tr>';
  129. }
  130. function abook_take_save()
  131. {
  132. global $username, $data_dir;
  133. global $abook_take_abook_take_location;
  134. global $abook_take_abook_take_hide;
  135. global $abook_take_abook_take_verify;
  136. if (isset($abook_take_abook_take_location))
  137. {
  138. setPref($data_dir, $username, 'abook_take_location', $abook_take_abook_take_location);
  139. }
  140. else
  141. {
  142. setPref($data_dir, $username, 'abook_take_location', 'center');
  143. }
  144. if (isset($abook_take_abook_take_hide))
  145. {
  146. setPref($data_dir, $username, 'abook_take_hide', '1');
  147. }
  148. else
  149. {
  150. setPref($data_dir, $username, 'abook_take_hide', '');
  151. }
  152. if (isset($abook_take_abook_take_verify))
  153. {
  154. setPref($data_dir, $username, 'abook_take_verify', '1');
  155. }
  156. else
  157. {
  158. setPref($data_dir, $username, 'abook_take_verify', '');
  159. }
  160. }
  161. ?>