Permalink
Browse files

move some field validation to builMailData

  • Loading branch information...
1 parent 201fe31 commit 793bdbd61cfee36cca0329cb470d34a69f7057f3 MattiasWiesner committed Feb 16, 2012
Showing with 11 additions and 8 deletions.
  1. +11 −8 incomingMail.php
View
@@ -48,11 +48,18 @@ function verifySignature(){
/**
* build the mailData object
- * feel free to validate the fields
+ * feel free to validate the fields as you need
* in case of invalid data return null
* @return \MailData
*/
function buildMailData() {
+ if(!isset($_POST['from'])
+ || !isset($_POST['to'])
+ || !isset($_POST['plain'])
+ || !isset($_POST['subject'])) {
+ return null;
+ }
+
$m = new MailData();
$m->from = $_POST['from'];
$m->to = $_POST['to'];
@@ -99,19 +106,15 @@ function handleMail(MailData $mailData) {
return $result;
}
-if(!isset($_POST['from'])
- || !isset($_POST['to'])
- || !isset($_POST['plain'])
- || !isset($_POST['subject'])) {
- myerror("missing data", 400);
-}
if (!verifySignature()) {
myerror('verification error', 403);
}
+
$mailData = buildMailData();
if(!$mailData) {
- myerror('invalid data', 400);
+ myerror('invalid or missing data', 400);
}
+
if(!handleMail($mailData)){
myerror('database error', 500);
}

0 comments on commit 793bdbd

Please sign in to comment.