1

I've got a set of arrays of string from imap_fetchstructure. But I can't extract the string out of the set. I need the value of [filePath] so I've silly tried

echo [attachments:protected][filePath];

And it doesn't work at all. I'm so new to this kind of array... This is the sample of an array set.

By the way these lines are getting from this:

$mailStructure = imap_fetchstructure($this->getImapStream(), $mailId, FT_UID);

Which is $this->getImapStream() comes from a class ImapMailbox.php

IncomingMail Object ( 
    [id] => 2687 
    [date] => 2014-08-07 16:53:11 
    [subject] => test attc 
    [fromName] => Hello Kitty 
    [fromAddress] => [email protected] 
    [to] => Array (
        [[email protected]] => sales 
    ) 
    [toString] => sales 
    [cc] => Array ( ) 
    [replyTo] => Array (
        [[email protected]] => Hello Kitty 
    ) 
    [textPlain] => testing for attachment 
    [textHtml] => testing for attachment
    [attachments:protected] => Array (
        [487540462265330294] => IncomingMailAttachment Object  ( 
             [id] => 487540462265330294 
             [name] => america_support_taks.jpg 
             [filePath] => /home/hellokitty/domains/hellokitty.com/public_html/email/inc/2687_487540462265330294_america_support_taks.jpg 
       ) 
   )
) 
8
  • What code generates this output? Commented Aug 7, 2014 at 12:44
  • There might be an accessor method for getting at the filename that you want to retrieve - what are you using to retrieve/generate this data? Commented Aug 7, 2014 at 12:51
  • Btw this object is not coming from imap_fetchstructure, compare to the return description in the manual. Commented Aug 7, 2014 at 12:52
  • The attachements property is protected, thus there must be a public getter. Try to access the filePath by $incomingMail->attachements['487540462265330294']->filePath Commented Aug 7, 2014 at 12:54
  • @SanderKoedood, it's from a class ImapMailbox.php which I already update the source. Please follow. Thank you. Commented Aug 7, 2014 at 12:59

1 Answer 1

1

The answer is easy and the methods can be found in the link you provided.

The attachments are a protected property of the IncomingMail object (see line 558) but a few lines further down there is a public method getAttachments() (line 567). The object IncomingMailAttachment has only 3 properties of which all are marked public (line 589).

$attachments = $mailStructure->getAttachments();

foreach ($attachments as $attachment) {
    // Array of IncomingMailAttachment objects
    echo $attachment->filePath;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Dan, Thank you very much. For an answer. The method works great after a little change from getAttachements() into getAttachments() - no 'e' after 'h'. :D
Dan, Thank you very much. Anyway I know that a silly question but again, thanks for your time.
It's not a silly question at all! I think the readers were just confused when you didn't link the library from github.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.