Coder Social home page Coder Social logo

Undefined property: stdClass::$bytes about fetch HOT 3 OPEN

tedious avatar tedious commented on July 20, 2024 1
Undefined property: stdClass::$bytes

from fetch.

Comments (3)

mfutselaar avatar mfutselaar commented on July 20, 2024

Did the same to "fix" this issue, please take a look into it and make a proper fix?

from fetch.

tedivm avatar tedivm commented on July 20, 2024

Feel free to make a pull request.

from fetch.

deemyboy avatar deemyboy commented on July 20, 2024

I wrapped that line in isset

Attachment.php:101

  if (isset($structure->bytes)) {
            $this->size = $structure->bytes;
        } else {
            $this->size = 0; // _mysql complained on null so I made the size 0_
        }

but now get some odd output and more attachments than were actually attached to the email

Here are my attachments

Number of attachments = 8 in total

screen shot 2016-11-23 at 09 01 15

Here is my debug code in this function

Attachment.php saveAS() function

   /**
     * This function saves the attachment to the exact specified location.
     *
     * @param  string $path
     * @return bool
     */
    public function saveAs($path)
    {
        $encoding = $this->encoding;
        $dirname = dirname($path);
        if (file_exists($path)) {
            if (!is_writable($path)) {
                return false;
            }
        } elseif (!is_dir($dirname) || !is_writable($dirname)) {
            return false;
        }

        if (($filePointer = fopen($path, 'w')) == false) {
            return false;
        }
        **echo "ATTACHMENT.PHP saveAs() filePointer is $filePointer.\n";**

        switch ($encoding) {
            case 3: //base64
                $streamFilter = stream_filter_append($filePointer, 'convert.base64-decode', STREAM_FILTER_WRITE);
                break;

            case 4: //quoted-printable
                $streamFilter = stream_filter_append($filePointer, 'convert.quoted-printable-decode', STREAM_FILTER_WRITE);
                break;

            default:
                $streamFilter = null;
        }

Here is the debug output

[2016-11-23 09:12:48] [Email Bookings] Successfully created a new task with id [59607]
You have new mail in /var/mail/nadeem
iMac:seraph3 nadeem$ php artisan bookings:email
this size is 6451
this size is 16057
this size is 0
this size is 16057
this size is 0
this size is 51521
this size is 0
this size is 10799
this size is 0
this size is 14830
this size is 0
this size is 10644
this size is 0
this size is 6454
[2016-11-23 09:13:18] [Email Bookings] Message from staff
[2016-11-23 09:13:18] [Email Bookings] Preparing to book the message in from [email protected]
[2016-11-23 09:13:18] [Email Bookings] Searching for [email protected] within site users
Message.php getAttachments() filename is 
[2016-11-23 09:13:18] [Email Bookings] Getting attachments
[2016-11-23 09:13:18] [Email Bookings] Has attachments
ATTACHMENT.PHP saveAs() filePointer is Resource id #748.
ATTACHMENT.PHP saveAs() filePointer is Resource id #750.
ATTACHMENT.PHP saveAs() filePointer is Resource id #751.
ATTACHMENT.PHP saveAs() filePointer is Resource id #752.
ATTACHMENT.PHP saveAs() filePointer is Resource id #753.
ATTACHMENT.PHP saveAs() filePointer is Resource id #754.
ATTACHMENT.PHP saveAs() filePointer is Resource id #755.
ATTACHMENT.PHP saveAs() filePointer is Resource id #756.
ATTACHMENT.PHP saveAs() filePointer is Resource id #757.
ATTACHMENT.PHP saveAs() filePointer is Resource id #758.
ATTACHMENT.PHP saveAs() filePointer is Resource id #759.
ATTACHMENT.PHP saveAs() filePointer is Resource id #760.
ATTACHMENT.PHP saveAs() filePointer is Resource id #761.
ATTACHMENT.PHP saveAs() filePointer is Resource id #762.
[2016-11-23 09:13:19] [Email Bookings] Successfully created a new task with id [59608]

and here are my attachments saved in my application.

screen shot 2016-11-23 at 09 16 55

It's hard to see exactly how many are being attached - there are 14 font awesome file/document icons and 17 delete icons (red x's) so does anybody have a clue why there are more attachments being created than actual real attachments?

I think it's got something to do with reading the structure of each section to find any attachments in each section.

Attachments.php:14

/**
 * This library is a wrapper around the Imap library functions included in php. This class wraps around an attachment
 * in a message, allowing developers to easily save or display attachments.
 *
 * @package Fetch
 * @author  Robert Hafner <[email protected]>
 */
class Attachment
{

    /**
     * This is the structure object for the piece of the message body that the attachment is located it.
     *
     * @var \stdClass
     */
    protected $structure;

    /**
     * This is the unique identifier for the message this attachment belongs to.
     *
     * @var int
     */
    protected $messageId;

    /**
     * This is the ImapResource.
     *
     * @var resource
     */
    protected $imapStream;

    /**
     * This is the id pointing to the section of the message body that contains the attachment.
     *
     * @var int
     */
    protected $partId;

    /**
     * This is the attachments filename.
     *
     * @var string
     */
    protected $filename;

    /**
     * This is the size of the attachment.
     *
     * @var int
     */
    protected $size;

    /**
     * This stores the data of the attachment so it doesn't have to be retrieved from the server multiple times. It is
     * only populated if the getData() function is called and should not be directly used.
     *
     * @internal
     * @var array
     */
    protected $data;

Clearly the above variables show this file handles attachments.

Help would be appreciated!

PS. This function's comments are incomplete so it's not easy to understand

Message.php:702

 /**
     * This function returns the attachments a message contains. If a filename is passed then just that ImapAttachment
     * is returned, unless
     *
     * @param  null|string $filename
     * @return array|bool|Attachment[]
     */
    public function getAttachments($filename = null)
    {
        echo "Message.php getAttachments() filename is $filename\n";
//        echo "Message.php getAttachments() this->attachments";
//        print_r($this->attachments);
//        echo "\n";

        if (!isset($this->attachments) || count($this->attachments) < 1)
            return false;

        if (!isset($filename))
            return $this->attachments;

        $results = array();
        foreach ($this->attachments as $attachment) {
            if ($attachment->getFileName() == $filename)
                $results[] = $attachment;
        }

        switch (count($results)) {
            case 0:
                return false;

            case 1:
                return array_shift($results);

            default:
                return $results;
                break;
        }
    }

from fetch.

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.