PHP Conference Kansai 2025

imap_savebody

(PHP 5 >= 5.1.3, PHP 7, PHP 8)

imap_savebodyGuarda una parte específica del cuerpo en un fichero

Descripción

imap_savebody(
    IMAP\Connection $imap,
    resource|string|int $file,
    int $message_num,
    string $section = "",
    int $flags = 0
): bool

Guarda una parte del cuerpo del mensaje especificado.

Parámetros

imap

An IMAP\Connection instance.

file

La ruta hacia el fichero de guardado, en forma de una string o un descriptor de fichero válido devuelto por la función fopen().

message_num

El número del mensaje

section

El número de la sección. Es una string de enteros, delimitados por una coma que corresponden al índice en la lista de secciones del cuerpo, tal como se prevé en la especificación IMAP4.

flags

Una máscara que contiene una o más de las siguientes valores:

  • FT_UID - El número message_num es un UID
  • FT_PEEK - No definir el flag \Seen si no está ya definido
  • FT_INTERNAL - La string devuelta está en un formato interno, que no corresponde a CRLF.

Valores devueltos

Devuelve true en caso de éxito o false en caso de error.

Historial de cambios

Versión Descripción
8.1.0 The imap parameter expects an IMAP\Connection instance now; previously, a valid imap recurso was expected.

Ver también

add a note

User Contributed Notes 1 note

up
13
anon
12 years ago
By using imap_fetchbody() you may run in trouble by using too much memory. Using imap_savebody() may prevent this.

But the content will be encoded, in other words it is useless. Adding a filter can help here.

<?php
$whandle
= fopen('./incomming/tmp.tif','w');

stream_filter_append($whandle,
'convert.base64-decode',STREAM_FILTER_WRITE);

imap_savebody ($mbox, $whandle, $i, $partcounter++);

fclose($whandle);
?>

NOTE: To find the proper filter you need to check the encoding given by the structure of the body.
To Top