Browse files

CI_Email::print_debugger() option to limit the type of data to be pri…

…nted

(an alternative to PR #1759; partially solves issue #1742)
  • Loading branch information...
1 parent cff3580 commit 61797f67a9bcb357ae7e1be9dadffd58eaa3e540 @narfbg narfbg committed Nov 26, 2012
Showing with 35 additions and 3 deletions.
  1. +23 −2 system/libraries/Email.php
  2. +1 −0 user_guide_src/source/changelog.rst
  3. +11 −1 user_guide_src/source/libraries/email.rst
View
25 system/libraries/Email.php
@@ -2062,9 +2062,11 @@ protected function _get_hostname()
/**
* Get Debug Message
*
+ * @param array $include List of raw data chunks to include in the output
+ * Valid options are: 'headers', 'subject', 'body'
* @return string
*/
- public function print_debugger()
+ public function print_debugger($include = array('headers', 'subject', 'body'))
{
$msg = '';
@@ -2076,7 +2078,26 @@ public function print_debugger()
}
}
- return $msg.'<pre>'.$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
+ // Determine which parts of our raw data needs to be printed
+ $raw_data = '';
+ is_array($include) OR $include = array($include);
+
+ if (in_array('headers', $include, TRUE))
+ {
+ $raw_data = $this->_header_str."\n";
+ }
+
+ if (in_array('subject', $include, TRUE))
+ {
+ $raw_data .= htmlspecialchars($this->_subject)."\n";
+ }
+
+ if (in_array('body', $include, TRUE))
+ {
+ $raw_data .= htmlspecialchars($this->_finalbody);
+ }
+
+ return $msg.($raw_data === '' ? '' : '<pre>'.$raw_data.'</pre>');
}
// --------------------------------------------------------------------
View
1 user_guide_src/source/changelog.rst
@@ -242,6 +242,7 @@ Release Date: Not Released
- Default charset now relies on the global ``$config['charset']`` setting.
- Removed unused protected method ``_get_ip()`` (:doc:`Input Library <libraries/input>`'s ``ip_address()`` should be used anyway).
- Internal method ``_prep_q_encoding()`` now utilizes PHP's *mbstring* and *iconv* extensions (when available) and no longer has a second (``$from``) argument.
+ - Added an optional parameter to ``print_debugger()`` to allow specifying which parts of the message should be printed ('headers', 'subject', 'body').
- :doc:`Pagination Library <libraries/pagination>` changes include:
- Added support for the anchor "rel" attribute.
- Added support for setting custom attributes.
View
12 user_guide_src/source/libraries/email.rst
@@ -268,11 +268,21 @@ parameter as mime-type::
$this->email->attach($buffer, 'attachment', 'report.pdf', 'application/pdf');
$this->email->print_debugger()
--------------------------------
+------------------------------
Returns a string containing any server messages, the email headers, and
the email messsage. Useful for debugging.
+You can optionally specify which parts of the message should be printed.
+Valid options are: **headers**, **subject**, **body**.
+
+Example::
+
+ // Will only print the email headers, excluding the message subject and body
+ $this->email->print_debugger(array('headers'));
+
+.. note:: By default, all of the raw data will be printed.
+
Overriding Word Wrapping
========================

0 comments on commit 61797f6

Please sign in to comment.