GithubHelp home page GithubHelp logo

Comments (14)

TTouka avatar TTouka commented on August 22, 2024 3

This issue may be fixed by using mb_convert_encoding instead of iconv.
(The illegal bytes will be dropped.)

A mismatch between an input string and a character set specified in 1st option triggers that error.

from php-imap.

barbushin avatar barbushin commented on August 22, 2024

I have pushed some fix eb27422

Does it helps?

from php-imap.

georaldc avatar georaldc commented on August 22, 2024

This does not seem to fix the issue because I'm running into the same thing too

EDIT:
I think #25 fixes the issue I'm having because the email I ran into with iconv issues was one where iconv was being applied to an attachment. I can probably compile the suggestions by @Kethryweryn into a pull request if it hasn't been done yet.

from php-imap.

aymanrb avatar aymanrb commented on August 22, 2024

Well as mentioned by @TTouka replacing iconv with mb_convert_encoding should fix it.

If you still prefer to keep iconv for its wider encoding coverage then the '//IGNORE' flag solves part of this issue.

You still need to check that the value of the first and second parameters of the iconv method (encoding from and to values) are not the same before calling the iconv. If both values match you should return the string directly without trying to convert it since here in this case the illegal characters doesn't seem to be ignored and the conversion fails returning false.

Reference: http://stackoverflow.com/questions/9375909/iconv-utf-8-ignore-still-produces-illegal-character-error

I would personally prefer the mb_convert_encoding solution proposed by @TTouka

from php-imap.

patie avatar patie commented on August 22, 2024

any news ?

from php-imap.

menzo avatar menzo commented on August 22, 2024

I have the same issue. Is there any news with this?
I've silenced the iconv (with @) in line 473, but a permanent fix would be better.

from php-imap.

barbushin avatar barbushin commented on August 22, 2024

No ideas. May be somebody can do good proper pull request?

from php-imap.

aymanrb avatar aymanrb commented on August 22, 2024

Thanks @barbushin and @georaldc for the latest implementation. Seemed to be the prettiest was to use mb_convert_encoding yet still keep iconv for other installations.

Now since you already made the check that the from and to encoding charsets are different then I would personally prefer to remove the mb_convert_encoding usage since it lacks support to a bunch of encodings (see supported ones here: http://php.net/manual/en/mbstring.encodings.php)

It keeps failing to return the correct decoded string for things like "windows-1256" and "GB2312"

from php-imap.

georaldc avatar georaldc commented on August 22, 2024

@aymanrb I see. That might be the reason why others are still running into issues. Are you suggesting to just drop mb_convert_encoding and use iconv?

from php-imap.

aymanrb avatar aymanrb commented on August 22, 2024

Yes, so far that worked for me, initially it caused issues cus the '//ignore' flag was not used and cuz we sometimes asked it to convert utf-8 to utf-8 and that failed resulting in an empty string.

Now with the double conditions we have there iconv should be more efficient (at least my test results says that)

from php-imap.

TTouka avatar TTouka commented on August 22, 2024

Thanks for implementation of my suggestion.

Dropping mb_convert_encoding is not good idea.
//IGNORE flag affects only output, so when iconv received broken string, it cannot convert the string.

So, using both functions may solve those issues:

  1. Convert given string with @iconv().
  2. When iconv() returns false, try to convert that string with mb_convert_encoding().
  3. When iconv() returns string, finish converting.

from php-imap.

aymanrb avatar aymanrb commented on August 22, 2024

Ok that would be a better implementation

from php-imap.

shdinx avatar shdinx commented on August 22, 2024

Adding to this whole converting issue - you probably should consider to silence mb_convert_encoding as well.

I have a string which is in a Semitic language ( WINDOWS-1256 ) and you try to convert it with mb_convert_encoding as long as we have loaded the mbstring extension.

However, mb_convert_encoding does not support WINDOWS-1256 as seen here: http://php.net/manual/en/function.mb-list-encodings.php

iconv() on the other hand does: http://www.gnu.org/software/libiconv/

Based on this RFC document it is a valid charset: http://www.iana.org/assignments/character-sets/character-sets.xhtml

We need to manage this case or otherwise we will end up with the warning from mb_convert_encoding.

A possible solution could be this mapping: https://rayed.com/wordpress/wp-content/upload/lib.utf2win.php.txt

from php-imap.

barbushin avatar barbushin commented on August 22, 2024

@shdinx How do you think, may be we can just do something like this:

$convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding) ? : @iconv($fromEncoding, $toEncoding . '//IGNORE', $string);

?

from php-imap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.