diff --git a/bootstrap.php b/bootstrap.php
index 7d589e33518e1e362210104132a875e6bea6f6f7..0a50c4a2635b693e575d87a3a13dda9f66e3a997 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -199,9 +199,18 @@ class Bootstrap {
                     return iconv($from, $to, $str); }
             }
             else {
-                function mb_strpos($a, $b) { return strpos($a, $b); }
-                function mb_strlen($str) { return strlen($str); }
-                function mb_substr($a, $b, $c=null) { return substr($a, $b, $c); }
+                function mb_strpos($a, $b) {
+                    $c = preg_replace('/^(\X*)'.preg_quote($b).'.*$/us', '$1', $a);
+                    return ($c===$a) ? false : mb_strlen($c);
+                }
+                function mb_strlen($str) {
+                    $a = array();
+                    return preg_match_all('/\X/u', $str, $a);
+                }
+                function mb_substr($a, $b, $c=null) {
+                    return preg_replace(
+                        "/^\X{{$b}}(\X".($c ? "{{$c}}" : "*").").*/us",'$1',$a);
+                }
                 function mb_convert_encoding($str, $to, $from='utf-8') {
                     if (strcasecmp($to, $from) == 0)
                         return $str;
diff --git a/include/ajax.reports.php b/include/ajax.reports.php
index 603fb41685e0c752ca6091edb451dab256309ecd..33512dd8936cb8926967c06f8c2ed379be568dc2 100644
--- a/include/ajax.reports.php
+++ b/include/ajax.reports.php
@@ -37,17 +37,7 @@ class OverviewReportAjaxAPI extends AjaxController {
     function getData() {
         global $thisstaff;
 
-        if(($start = $this->get('start', 'last month'))) {
-            $stop = $this->get('stop', 'now');
-            if (substr($stop, 0, 1) == '+')
-                $stop = $start . $stop;
-        } else {
-            $start = 'last month';
-            $stop = 'now';
-        }
-
-        $start = 'FROM_UNIXTIME('.strtotime($start).')';
-        $stop = 'FROM_UNIXTIME('.strtotime($stop).')';
+        list($start, $stop) = $this->_getDateRange();
 
         $groups = array(
             "dept" => array(
@@ -172,26 +162,38 @@ class OverviewReportAjaxAPI extends AjaxController {
             'text/csv', $csv);
     }
 
-    function getPlotData() {
-
+    function _getDateRange() {
+        global $cfg;
 
         if(($start = $this->get('start', 'last month'))) {
-            $stop = $this->get('stop', 'now');
-            if (substr($stop, 0, 1) == '+')
-                $stop = $start . $stop;
+            $stop = $this->get('period', 'now');
         } else {
             $start = 'last month';
-            $stop = 'now';
+            $stop = $this->get('period', 'now');
         }
 
-        $start = strtotime($start);
-        $stop = strtotime($stop);
+        if ($start != 'last month')
+            $start = DateTime::createFromFormat($cfg->getDateFormat(),
+                $start)->format('U');
+        else
+            $start = strtotime($start);
+
+        if (substr($stop, 0, 1) == '+')
+            $stop = strftime('%Y-%m-%d ', $start) . $stop;
+
+        $start = 'FROM_UNIXTIME('.$start.')';
+        $stop = 'FROM_UNIXTIME('.strtotime($stop).')';
+
+        return array($start, $stop);
+    }
+
+    function getPlotData() {
+        list($start, $stop) = $this->_getDateRange();
 
         # Fetch all types of events over the timeframe
         $res = db_query('SELECT DISTINCT(state) FROM '.TICKET_EVENT_TABLE
-            .' WHERE timestamp BETWEEN FROM_UNIXTIME('.db_input($start)
-                .') AND FROM_UNIXTIME('.db_input($stop)
-                .') ORDER BY 1');
+            .' WHERE timestamp BETWEEN '.$start.' AND '.$stop
+                .' ORDER BY 1');
         $events = array();
         while ($row = db_fetch_row($res)) $events[] = $row[0];
 
@@ -200,9 +202,8 @@ class OverviewReportAjaxAPI extends AjaxController {
         $res = db_query('SELECT state, DATE_FORMAT(timestamp, \'%Y-%m-%d\'), '
                 .'COUNT(ticket_id)'
             .' FROM '.TICKET_EVENT_TABLE
-            .' WHERE timestamp BETWEEN FROM_UNIXTIME('.db_input($start)
-                .') AND FROM_UNIXTIME('.db_input($stop)
-            .') AND NOT annulled'
+            .' WHERE timestamp BETWEEN '.$start.' AND '.$stop
+            .' AND NOT annulled'
             .' GROUP BY state, DATE_FORMAT(timestamp, \'%Y-%m-%d\')'
             .' ORDER BY 2, 1');
         # Initialize array of plot values
diff --git a/include/class.config.php b/include/class.config.php
index 69e60dcf75f43ce18884157c6152e7df8d604af8..fd03f9c2ee38ba4b7278dc0dfc1b9dc7fd90f9e6 100644
--- a/include/class.config.php
+++ b/include/class.config.php
@@ -178,7 +178,7 @@ class OsticketConfig extends Config {
         return true;
     }
 
-    function lastModified() {
+    function lastModified($key=false) {
         return max(array_map(array('parent', 'lastModified'),
             array_keys($this->config)));
     }
diff --git a/include/class.format.php b/include/class.format.php
index c8980326d08c7b404e8511942f35aebd0d79204c..8ee72d8d36ecf2a42ebea095114f9a36c8efd26d 100644
--- a/include/class.format.php
+++ b/include/class.format.php
@@ -42,9 +42,6 @@ class Format {
                 array('default','x-user-defined','iso','us-ascii')))
             $charset = 'ISO-8859-1';
 
-        if ($charset && strcasecmp($charset, $encoding) === 0)
-            return $text;
-
         $original = $text;
         if(function_exists('iconv') && $charset)
             $text = iconv($charset, $encoding.'//IGNORE', $text);
diff --git a/include/class.mailparse.php b/include/class.mailparse.php
index 3a49a66b5dd3398142458a229781d75f50505b0f..c596e7ac4071ec98f1a970fadd1a9f7311abab07 100644
--- a/include/class.mailparse.php
+++ b/include/class.mailparse.php
@@ -66,7 +66,20 @@ class Mail_Parse {
             $outer = $this->struct;
             $ctype = $outer->ctype_primary.'/'.$outer->ctype_secondary;
             if (strcasecmp($ctype, 'message/rfc822') === 0) {
+                // Capture Delivered-To header from the outer mail
+                $dt = $this->struct->headers['delivered-to'];
+                // Capture Message-Id from outer mail
+                $mid = $this->struct->headers['message-id'];
+
                 $this->struct = $outer->parts[0];
+
+                // Add (clobber) delivered to header from the outer mail
+                if ($dt)
+                    $this->struct->headers['delivered-to'] = $dt;
+                // Ensure the nested mail has a Message-Id
+                if (!isset($this->struct->headers['message-id']))
+                    $this->struct->headers['message-id'] = $mid;
+
                 // Use headers of the wrapped message
                 $headers = array();
                 foreach ($this->struct->headers as $h=>$v)
@@ -186,7 +199,9 @@ class Mail_Parse {
     }
 
     function getMessageId(){
-        return $this->struct->headers['message-id'];
+        if (!($mid = $this->struct->headers['message-id']))
+            $mid = sprintf('<%s@local>', md5($this->getHeader()));
+        return $mid;
     }
 
     function getSubject(){