[dev] Opening E-Mails via IMP

Michael J Rubinsky mrubinsk at horde.org
Tue Sep 17 02:59:03 UTC 2019


Quoting Sebastian Birnbach <birnbacs at gmail.com>:

> Thanks Michael, that looks promising.
>
> Pardon my ignorance but where do I go from there? The API gives me a
> Horde_Imap_Client_Base object which I probably use to get a
> Horde_Imap_Client_Mailbox, OK.  But I cannot see how to access a message
> from there. What am I missing?


Thomas replied with some good general overview of how to work with the  
client; I'll add some more information specific to what I think you  
are doing. This code assumes you are within the context of a Horde  
application, and that authentication is also valid for IMP. I'm also  
assuming you have the UID of the specific message you want and that  
you plan on displaying some part of it. For this example, I'll assume  
it's one of the main body parts and not an attachment.

// imap object
$imap = $GLOBALS['registry']->mail->imapOb();

// Use the INBOX
$mbox = Horde_Imap_Client_Mailbox::get('INBOX');

// Build a query for the imap server
$query = new Horde_Imap_Client_Fetch_Query();

// Indicate we want the mime structure of the message.
$query->structure();

// If you want flag data...
$query->flags();

// You probably want/need the envelope data
$query->envelope();

// If you want/need the header text, but just peek so we don't set the  
/seen flag.
$query->headerText(array('peek' => true));

// Array of UIDS that you want to fetch.
$uids = array(100, 101);

// Get the results from the server.
$fetch_results = imap->fetch($mbox, $query, array('ids' => new  
Horde_Imap_Client_Ids($uids), 'exists' => true));

// You can access the results like so:
$data = $fetch_results[$uuid];

// Get message headers (returns a Horde_Mime_Headers object)
$data->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);


// This is the base Horde_Mime object, describing the message structure.
$base_part = $data->getStructure();

// This is the mime_id of a plain text body part (if any).
$text_id = $basePart->findBody('plain');
$text_mime_part = $basePart->getPart($text_id);
$text_contents = $data->getBodyPart($text_id);

// Ensure its properly decoded if needed.
if (!$data->getBodyPartDecode($text_id))
     $text_mime_part->setContents($text_contents);
     $text_contents = $text_mime->getContents();
}

That should get you most of the way there. Obviously there is a LOT  
involved in properly fetching and decoding message data.  If you go  
this route, you'll want to be familiar with Horde_Mime and  
Horde_Imap_Client. See https://dev.horde.org/ for autogenerated phpdoc.

You can also look at the code in IMP or Horde_ActiveSync_Imap_Adapter,  
Horde_ActiveSync_Imap_Message, and Horde_ActiveSync_MessageBodyData  
for some more usage...


> Am Do., 5. Sept. 2019 um 15:28 Uhr schrieb Michael J Rubinsky <
> mrubinsk at horde.org>:
>
>>
>> Quoting Sebastian Birnbach <birnbacs at gmail.com>:
>>
>> > In my own Horde file management application I whish to link entries
>> > ("dossiers") to E-Mail messages. The idea is to keep a message's UID as a
>> > reference in the dossier and open the message for closer inspection upon
>> if
>> > the user so whishes. I imagine opening a new IMP window with the message,
>> > enabling the user to answer, download, forward etc.
>> >
>> > Is there a way to open an E-Mail message of known UID and mailbox from
>> > another Horde application *in IMP* ? I had a look at IMP_Api and find
>> > nothing helpful.
>>
>> Off the top of my head, because of the way IMP caches message
>> information, I don't think it's currently possible to open an IMP
>> message view window referencing only an IMAP UID via code from another
>> application.
>>
>> Your statement about using IMAP directly needing extra authentication
>> isn't exactly correct. You can use IMP_Api::imapOb() to get a
>> reference to the Horde_Imap_Client object, already authenticated
>> (assuming IMP uses "hordeauth" or the user is already otherwise
>> authenticated to IMP).  You can then use the Horde_Imap_Client object
>> to fetch what you need to display.
>>
>>
>> > Note: just displaying the message should be feasible using PHP:IMAP but
>> > that would require an extra authentication step and is not exactly an
>> > integration of applications.
>> > --
>> > dev mailing list
>> > Frequently Asked Questions: http://wiki.horde.org/FAQ
>> > To unsubscribe, mail: dev-unsubscribe at lists.horde.org
>>
>>
>>
>> --
>> mike
>> The Horde Project
>> http://www.horde.org
>> https://www.facebook.com/hordeproject
>> https://www.twitter.com/hordeproject
>> --
>> dev mailing list
>> Frequently Asked Questions: http://wiki.horde.org/FAQ
>> To unsubscribe, mail: dev-unsubscribe at lists.horde.org
>>



-- 
mike
The Horde Project
http://www.horde.org
https://www.facebook.com/hordeproject
https://www.twitter.com/hordeproject
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-keys
Size: 9272 bytes
Desc: PGP Public Key
URL: <https://lists.horde.org/archives/dev/attachments/20190917/632a1144/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 851 bytes
Desc: PGP Digital Signature
URL: <https://lists.horde.org/archives/dev/attachments/20190917/632a1144/attachment-0001.bin>


More information about the dev mailing list