Please tell me there is a code:
$stream = imap_open("{" . $arr["URL"] . "}INBOX", $arr["LOGIN"], $arr["PASS"], OP_READONLY); logfile("imap_open completed!"); if (!$stream) { AddMessage2Log(imap_errors()); } else { $search = imap_search($stream, $subject); foreach ($search as $keyMsgNum => $msgNum) { $structureMsg = imap_fetchstructure($stream, $msgNum); if (!empty($structureMsg->parts)) { foreach ($structureMsg->parts as $k => $part) { if ($part->disposition == "attachment" && strtolower($part->subtype) == $subtype) { $encoding = $part->encoding; $message = imap_fetchbody($stream, $msgNum, $k + 1); for a long time he could not get an attachment, found somewhere that when performing imap_fetchbody indicate section + 1, tried to work, but I can’t understand why +1 and where this +1 comes from when
echo "<pre>"; print_r($structureMsg); echo "</pre>"; we receive 2 parts and further we select only that from which attachment
stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => MIXED [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => boundary [value] => ------------FE0E820A693934CE1B483ED5 ) ) [parts] => Array ( [0] => stdClass Object ( [type] => 0 [encoding] => 1 [ifsubtype] => 1 [subtype] => PLAIN [ifdescription] => 0 [ifid] => 0 [lines] => 7 [bytes] => 116 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => charset [value] => utf-8 ) ) ) [1] => stdClass Object ( [type] => 0 [encoding] => 4 [ifsubtype] => 1 [subtype] => XML [ifdescription] => 0 [ifid] => 0 [lines] => 23524 [bytes] => 1792583 [ifdisposition] => 1 [disposition] => attachment [ifdparameters] => 1 [dparameters] => Array ( [0] => stdClass Object ( [attribute] => filename [value] => ISTOCHNIK_20190508_232040.xml ) ) [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => name [value] => ISTOCHNIK_20190508_232040.xml ) ) ) ) )