Comments (14)
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.
I have pushed some fix eb27422
Does it helps?
from php-imap.
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.
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.
any news ?
from php-imap.
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.
No ideas. May be somebody can do good proper pull request?
from php-imap.
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.
@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.
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.
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:
- Convert given string with
@iconv()
. - When
iconv()
returnsfalse
, try to convert that string withmb_convert_encoding()
. - When
iconv()
returnsstring
, finish converting.
from php-imap.
Ok that would be a better implementation
from php-imap.
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.
@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)
- [Feature Request] I Want to All Email in Directory and Spam Directory
- [Feature Request] Add Origin-MessageID header
- Couldn't open stream
- PHP Fatal error: Uncaught Error: Call to protected method PhpImap\Mailbox::disconnect()
- I need solution for convert emails to ticket
- Can not authenticate to IMAP server: [AUTHENTICATIONFAILED] Invalid credentials (Failure)PHP Notice: Unknown: Can not authenticate to IMAP server: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=2) in Unknown on line 0
- ConnectionException "LOGIN failed." with office 365 since Microsoft activated two factor auth HOT 2
- [Feature Request] Add bool return to setFlag(), markMailAsRead(), etc. HOT 2
- fetch_overview does not allow select range with * HOT 1
- [BUG] Embeded images get replaced nok HOT 1
- [BUG] Processing ENCBINARY encoding returned base64 string
- [BUG] For some emails, the body is empty HOT 3
- Error Handling Not working
- where is vendor folder HOT 7
- [BUG] Mark as Seen boolean not working on getMail() HOT 1
- imap_fetchheader(): UID does not exist HOT 2
- [Feature Request] Save email to eml file
- SEEN SINCE Issue
- OFFICE 365 - Connection HOT 1
- [BUG] Truncated Attachment Names Resulting in Lost File Extensions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-imap.