Welcome Guest, Not a member yet? Register   Sign In
E-mail and UTF-8, mb_, etc.
#1
Question 
(This post was last modified: 03-27-2024, 02:21 AM by joho.)

Looking at the Email class in CI4, shouldn't things like setMessage() and possibly other functions utilize mb_ functions for trimming, replacing, and so on to support multi-byte data properly? This includes functions like setReplyTo(), setFrom(), and setTo() in regards to the $name parameter, since it's technically possible (I think?) for these to contain multi-byte data.

It'd also be nice if the initialize() function had a bool parameter, $clearPrevious = true, that would allow calling initialize() multiple times for additive settings. Or, have another function, config(), which did not clear the previous configuration/settings.

With the disclaimer that I've just started looking into the Email class :-)

The automatic conversion from HTML to create a plain text part, should probably take <br> and <p> into account.

Replace all <br> and <br/> and <br /> to whatever the configured line ending is.
Replace all <p> with nothing, and </p> to two times whatever the configured line ending is.

I think it's reasonably safe to assume that if you have <br/> and <p> tags in your HTML, you'd want them to "carry" over to a plain text part in some way.

-joho
Reply
#2

My comments about multi-byte handling still stands, I created my own setMessageText() function that is a mix of what was there and something that handles <br/> and <p></p>. This assumes I send my message as HTML:

PHP Code:
public static function setMessageTextstring $message_text ) : void {
        self::checkSetup();
        self::$email->setAltMessage'' );
        self::$email->setMessage$message_text );

        $plain_text mb_eregi_replace'<br(\s?\/)?>'"\n"$message_text );
        $plain_text mb_eregi_replace'<p>'"\n"$plain_text );
        $plain_text mb_eregi_replace'</p>'"\n\n"$plain_text );

        $plain_text preg_match('/\<body.*?\>(.*)\<\/body\>/si'$plain_text$match) ? $match[1] : $plain_text;
        $plain_text str_replace("\t",
                                  '',
                                  preg_replace('#<!--(.*)--\>#',
                                              '',
                                              trimstrip_tags$plain_text ) )
                                  )
        );

        self::$email->setAltMessage$plain_text );
    

-joho
Reply




Theme © iAndrew 2016 - Forum software by © MyBB