Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting 'iconv(): Detected an incomplete multibyte character in input string' #265

Closed
RomanBurunkov opened this issue Sep 20, 2018 · 1 comment
Labels
needs investigation This will be tested / debugged or checked out. phpunit Adding or updating PHPUnit tests for this issue.

Comments

@RomanBurunkov
Copy link

RomanBurunkov commented Sep 20, 2018

Hi there,

I'm currently use version about 2.0.5...not sure which exactly because can't find version number in source code.

Quite often gets this error message during getting emails:

PhpImap/Mailbox.php; 628; iconv(): Detected an incomplete multibyte character in input string

At 628 row I got the following code:

	protected function convertStringEncoding($string, $fromEncoding, $toEncoding) {
		$convertedString = null;
		if($string && $fromEncoding != $toEncoding) {
			$convertedString = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string);
			if(!$convertedString && extension_loaded('mbstring')) {
				$convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding);
			}
		}
		return $convertedString ?: $string;
	}

I've tried to use convertStringEncoding from latest version:

	/**
	 * Converts a string from one encoding to another.
	 * @param string $string
	 * @param string $fromEncoding
	 * @param string $toEncoding
	 * @return string Converted string if conversion was successful, or the original string if not
	 * @throws Exception
	 */
	protected function convertStringEncoding($string, $fromEncoding, $toEncoding) {
		if(!$string || $fromEncoding == $toEncoding) {
			return $string;
		}
		$convertedString = function_exists('iconv') ? @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) : null;
		if(!$convertedString && extension_loaded('mbstring')) {
			$convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding);
		}
		if(!$convertedString) {
			throw new Exception('Mime string encoding conversion failed');
		}
		return $convertedString;
	}

But still got the same issue.

Is there any way to fix that?

@Sebbo94BY Sebbo94BY added needs investigation This will be tested / debugged or checked out. phpunit Adding or updating PHPUnit tests for this issue. labels May 9, 2019
@Sebbo94BY
Copy link
Collaborator

I've added a PHPUnit test. See referenced commit.

I can not reproduce this issue. Closing this for now since it's already really old.

I'll reopen this issue when you or somebody else can provide some example strings, which are causing this issue.

You also can open a new issue, if you want to.

Sebbo94BY added a commit that referenced this issue May 11, 2019
- Updated comments, made code a bit more dynamic, used setAttachmentsDir() in constructor
- Added condition for setting attachments dir in constructor
- Issue #232: Added test strings with emojis (smiles) to PHPUnit test
- Issue #232: Added strings to test decodeMimeStr() in PHPUnit test with non-UTF8 server encoding
- Issue #232: Fixed broken UTF-8 decoded strings, when not using UTF-8 as server encoding
- Issue #265: Added string to test iconv() in PHPUnit test
- Issue #274: Some strings with default charset had UTF-8 characters and failed to convert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation This will be tested / debugged or checked out. phpunit Adding or updating PHPUnit tests for this issue.
Projects
None yet
Development

No branches or pull requests

2 participants