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

Attachment id issue #31

Open
klysiak opened this issue Feb 6, 2020 · 11 comments
Open

Attachment id issue #31

klysiak opened this issue Feb 6, 2020 · 11 comments

Comments

@klysiak
Copy link

klysiak commented Feb 6, 2020

Hi,

I received an email with attachments and those were not recognized by your library.
The issue was that originally imap_fetchstructure got the following:

[type] => 3 [encoding] => 3 [ifsubtype] => 1 [subtype] => PDF [ifdescription] => 0 [ifid] => 1 [id] => <> [bytes] => 277320 [ifdisposition] => 1 [disposition] => attachment [ifdparameters] => 1
Your code:
$attachmentId = $partStructure->ifid ? trim($partStructure->id, " <>") : (isset($params['filename']) || isset($params['name']) ? mt_rand() . mt_rand() : null);

was generating empty $attachmentId so if($attachmentId) returned false and the attachments were not processed.

Temporarily I added
$attachmentId = $partStructure->ifid ? ((trim($partStructure->id, " <>") != '')?trim($partStructure->id, " <>"):mt_rand() . mt_rand()) : (isset($params['filename']) || isset($params['name']) ? mt_rand() . mt_rand() : null);

and it is working. I will check if it is causing any further issues.

Maybe you have better suggestion?

@yiioverflow
Copy link
Owner

Sure dear. Can you send me one pull request pls ?

@s1lver
Copy link
Contributor

s1lver commented May 5, 2020

This is a very bad construction

@yiioverflow
Copy link
Owner

Yes. So I didnt merged it yet.

@s1lver
Copy link
Contributor

s1lver commented May 5, 2020

I would suggest doing so, but check:

    /**
     * @param object $structure
     * @param array $params
     * @return string|null
     */
    public static function getAttachmentId($structure, $params): ?string
    {
        if ($structure->ifid && !empty(trim($structure->id, " <>"))) {
            $attachmentId = trim($structure->id, " <>");
        } elseif (isset($params['filename']) || isset($params['name'])) {
            $attachmentId = mt_rand() . mt_rand();
        } else {
            $attachmentId = null;
        }

        return $attachmentId;
    }

@yiioverflow
Copy link
Owner

@klysiak can you verify the above solution please ?

@klysiak
Copy link
Author

klysiak commented May 27, 2020

I have implemented suggested solution. First impression is good. It is working fine. Please give me few days to verify if all is correct.

@yiioverflow
Copy link
Owner

@klysiak okay, Thanks

@yiioverflow
Copy link
Owner

@klysiak did you get time check this ?

@yiioverflow
Copy link
Owner

I have implemented suggested solution. First impression is good. It is working fine. Please give me few days to verify if all is correct.

If you dont mind, Can you give me an update please ?

@garryseldon
Copy link

Hello. If the name of the attached file is too long, then the OS does not allow it to be saved. Can the file name be generated randomly, for example through the uniqid function? It would be nice not to save the files, but to get its contents through the method.

@s1lver
Copy link
Contributor

s1lver commented Aug 3, 2023

Hello. If the name of the attached file is too long, then the OS does not allow it to be saved. Can the file name be generated randomly, for example through the uniqid function? It would be nice not to save the files, but to get its contents through the method.

Yes it would be nice. We check the length of the file, if it is too large, then we replace it with a unique value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants