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

Error in code #86

Closed
joseph-batson opened this issue Jul 15, 2015 · 4 comments
Closed

Error in code #86

joseph-batson opened this issue Jul 15, 2015 · 4 comments
Labels
enhancement This will enhance this library.

Comments

@joseph-batson
Copy link

File: Mailbox.php
Line: 509

            $replace = array(
                '/\s/' => '_',
                '/[^0-9a-zа-яіїє_\.]/iu' => '',
                '/_+/' => '_',
                '/(^_)|(_$)/' => '',
            );

should be

            $replace = array(
                '/\s/' => '_',
                '/[^0-9a-zA-Z_\.]/' => '',
                '/_+/' => '_',
                '/(^_)|(_$)/' => '',
            );
@barbushin
Copy link
Owner

Why?)

@joseph-batson
Copy link
Author

In a previous version that was the regex that was used in method
initMailPart. Just looked wrong to me, if

If this

$replace = array(

'/\s/' => '_',

'/[^0-9a-zа-яіїє_.]/iu' => '',

'/+/' => '',

'/(^)|($)/' => '',

);

is correct let me know.

Thanks,
Joseph Batson
Web Developer
Email: mailto:jbatson@verifysystems.com jbatson@verifysystems.com
Verify Systems, Inc.


From: Sergey [mailto:notifications@github.com]
Sent: Friday, July 17, 2015 1:17 AM
To: barbushin/php-imap
Cc: joseph-batson
Subject: Re: [php-imap] Error in code (#86)

Why?)


Reply to this email directly or
#86 (comment)
view it on GitHub.
<https://github.com/notifications/beacon/AMvQfvhPDdEFEXOfHnQ_sC8GyBS7td4Mks5
oeJVpgaJpZM4FZfl9.gif>

@barbushin barbushin removed need help Your support is required to solve this issue. labels May 23, 2016
@Sebbo94BY
Copy link
Collaborator

@barbushin this is about this piece of code on L724-L730:

$replace = [
	'/\s/' => '_',
	'/[^0-9a-zа-яіїє_\.]/iu' => '',
	'/_+/' => '_',
	'/(^_)|(_$)/' => '',
];
$fileSysName = preg_replace('~[\\\\/]~', '', $mail->id . '_' . $attachmentId . '_' . preg_replace(array_keys($replace), $replace, $fileName));

In my opinion, I would change it to this regex: /[^\w\.]/iu

  • ^ Starting with...
  • \w Any word character (letter, number, underscore)
  • \. A dot (.)

So \w includes these characters:

  • 0-9
  • a-z
  • A-Z
  • _
  • яіїє

When you agree, I'll just change this single regex to my suggested solution.

@Sebbo94BY Sebbo94BY added the enhancement This will enhance this library. label May 1, 2019
@Sebbo94BY
Copy link
Collaborator

Tested the change and all is still working fine and as expected.

Sebbo94BY added a commit that referenced this issue May 5, 2019
- Updated README
- Move phpunit to require-dev
- Add note about installing dev dependencies in README
- Replaced spaces with tabs
- Added PHPUnit tests for MIME decoding
- Updated formatting of PHPUnit function testParsedDateTimeWithEmptyHeaderDate()
- Issue #209: Function to parse datetime correctly RFC2822
- Issue #280: Added 'Sender' to headers and added additional if-conditions 
- Issue #115: getMail() method returns an object even for nonexistent mail ID
- Issue #273: Added connection check to example
- Issue #227: Added Failed-Recipients to IncomingMailHeader
- Issue #140, #246: Improved exception handling and added PHPUnit test
- Issue #140: Added PHPUnit test for testing ConnectionException
- Issue #140: Improved exception / error handling and improved / added PHPUnit tests
- Issue #154: Added ability to change the imap_search option from SE_UID to SE_FREE and added PHPUnit tests
- Issue #306: Added support for US-ASCII and added ability to disable serverEncoding for searchMailbox()
- Imported missing namespaces to avoid 'unknown class' error messages
- Issue #86: Simplified and improved one replace regex for attachment file names
- Issue #247: Improved grabbing of fromName, fromHost, senderName and senderHost
- Issue #39, #71, #229: Fixed body content gets incorrectly processed as attachments
- Issue #122, #150, #167: Added ability to skip processing of attachments to increase performance, when attachments are not required
- PR #284: Added missing PHPUnit tests
- Issue #122, #150, #167: Lazy load message text and attachments data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This will enhance this library.
Projects
None yet
Development

No branches or pull requests

3 participants