-$headers = array('Date' => date('r'),
- 'From' => rcube_charset_convert($identity_arr['string'], RCMAIL_CHARSET, $message_charset),
- 'To' => $mailto);
+$headers = array();
+
+// if configured, the Received headers goes to top, for good measure
+if ($CONFIG['http_received_header'])
+{
+ $nldlm = $RCMAIL->config->header_delimiter() . "\t";
+ $http_header = 'from ';
+ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+ $http_header .= rcmail_encrypt_header(gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR'])) .
+ ' [' . rcmail_encrypt_header($_SERVER['HTTP_X_FORWARDED_FOR']) . ']';
+ $http_header .= $nldlm . ' via ';
+ }
+ $http_header .= rcmail_encrypt_header(gethostbyaddr($_SERVER['REMOTE_ADDR'])) .
+ ' [' . rcmail_encrypt_header($_SERVER['REMOTE_ADDR']) .']';
+ $http_header .= $nldlm . 'with ' . $_SERVER['SERVER_PROTOCOL'] .
+ ' ('.$_SERVER['REQUEST_METHOD'] . '); ' . date('r');
+ $http_header = wordwrap($http_header, 69, $nldlm);
+ $headers['Received'] = $http_header;
+}
+
+$headers['Date'] = date('r');
+$headers['From'] = rcube_charset_convert($identity_arr['string'], RCMAIL_CHARSET, $message_charset);
+$headers['To'] = $mailto;