From ad43e637bd51b5b288856fee9a69da851ba07779 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 26 Feb 2008 13:08:19 -0500
Subject: [PATCH] Add SMTP test to installer script

---
 installer/test.php |   67 +++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 1 deletions(-)

diff --git a/installer/test.php b/installer/test.php
index b782a5c..0f499eb 100644
--- a/installer/test.php
+++ b/installer/test.php
@@ -123,7 +123,72 @@
 
 ?>
 
-<p>[@todo Add tests for IMAP and SMTP settings]</p>
+<h3>Test SMTP settings</h3>
+
+<p>
+Server: <?php echo $RCI->getprop('smtp_server', 'PHP mail()'); ?><br />
+Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
+User: <?php echo $RCI->getprop('smtp_user', '(none)'); ?><br />
+Password: <?php echo $RCI->getprop('smtp_pass', '(none)'); ?><br />
+</p>
+
+<?php
+
+if (isset($_POST['sendmail']) && !empty($_POST['_from']) && !empty($_POST['_to'])) {
+  
+  require_once 'lib/rc_mail_mime.inc';
+  require_once 'include/rcube_smtp.inc';
+  
+  echo '<p>Trying to send email...<br />';
+  
+  if (preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_from'])) &&
+      preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_to']))) {
+  
+    $recipients = trim($_POST['_to']);
+
+    $headers = array(
+      'From' => trim($_POST['_from']),
+      'To'  => $recipients,
+      'Subject' => 'Test message from RoundCube',
+    );
+
+    $body = 'This is a test to confirm that RoundCube can send email.';
+
+    $mail_object  = new rc_mail_mime();
+    $send_headers = $mail_object->headers($headers);
+
+    $smtp_response = array();
+    $status = smtp_mail($headers['From'], $recipients,
+        ($foo = $mail_object->txtHeaders($send_headers)),
+        $body, $smtp_response);
+
+    if ($status) {
+        $RCI->pass('SMTP send');
+    }
+    else {
+        $RCI->fail('SMTP send', join('; ', $smtp_response));
+    }
+  }
+  else {
+    $RCI->fail('SMTP send', 'Invalid sender or recipient');
+  }
+}
+
+echo '</p>';
+
+?>
+
+<table>
+<tbody>
+  <tr><td><label for="sendmailfrom">Sender</label></td><td><input type="text" name="_from" value="" id="sendmailfrom" /></td></tr>
+  <tr><td><label for="sendmailto">Recipient</label></td><td><input type="text" name="_to" value="" id="sendmailto" /></td></tr>
+</tbody>
+</table>
+
+<p><input type="submit" name="sendmail" value="Send test mail" /></p>
+
+
+<p>[@todo Add tests for IMAP settings]</p>
 
 </form>
 

--
Gitblit v1.9.1