Conditions | 14 |
Paths | 800 |
Total Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
117 | // for complete safeness encode every character :) |
||
118 | if ($bEmulate_imap_8bit) |
||
119 | $sRegExp = '/[^\x20\x21-\x3C\x3E-\x7E]/'; |
||
120 | |||
121 | $sLine = preg_replace_callback( $sRegExp, 'mail_quotedprintable_encode_callback', $sLine ); |
||
122 | |||
123 | // encode x09,x20 at lineends |
||
124 | { |
||
125 | $iLength = strlen($sLine); |
||
126 | $iLastChar = ord($sLine[$iLength-1]); |
||
127 | |||
128 | // !!!!!!!! |
||
129 | // imap_8_bit does not encode x20 at the very end of a text, |
||
130 | // here is, where I don't agree with imap_8_bit, |
||
131 | // please correct me, if I'm wrong, |
||
132 | // or comment next line for RFC2045 conformance, if you like |
||
133 | if (!($bEmulate_imap_8bit && ($i==count($aLines)-1))){ |
||
134 | if (($iLastChar==0x09)||($iLastChar==0x20)) { |
||
135 | $sLine[$iLength-1]='='; |
||
136 | $sLine .= ($iLastChar==0x09)?'09':'20'; |
||
137 | } |
||
138 | } |
||
139 | } // imap_8bit encodes x20 before chr(13), too |
||
140 | // although IMHO not requested by RFC2045, why not do it safer :) |
||
141 | // and why not encode any x20 around chr(10) or chr(13) |
||
142 | if ($bEmulate_imap_8bit) { |
||
143 | $sLine=str_replace(' =0D','=20=0D',$sLine); |
||
144 | //$sLine=str_replace(' =0A','=20=0A',$sLine); |
||
145 | //$sLine=str_replace('=0D ','=0D=20',$sLine); |
||
146 | //$sLine=str_replace('=0A ','=0A=20',$sLine); |
||
147 | } |
||
148 | |||
149 | // finally split into softlines no longer than $maxlen chars, |
||
150 | // for even more safeness one could encode x09,x20 |
||
151 | // at the very first character of the line |
||
152 | // and after soft linebreaks, as well, |
||
153 | // but this wouldn't be caught by such an easy RegExp |
||
154 | if($maxlen){ |
||
155 | preg_match_all( '/.{1,'.($maxlen - 2).'}([^=]{0,2})?/', $sLine, $aMatch ); |
||
156 | $sLine = implode( '=' . MAILHEADER_EOL, $aMatch[0] ); // add soft crlf's |
||
157 | } |
||
158 | } |
||
159 | |||
160 | // join lines into text |
||
161 | return implode(MAILHEADER_EOL,$aLines); |
||
162 | } |
||
163 | |||
164 | function mail_quotedprintable_encode_callback($matches){ |
||
165 | return sprintf( "=%02X", ord ( $matches[0] ) ) ; |
||
166 | } |
||
167 |