PHP: Problems with Microsoft Exchange, no have body of email in PHP - php

I have a litte problem with imap_fetchstructure, Microsoft SMTP Server (?) and signed mails by application/pkcs7-signature. Normally when I send signed email to gmail server I don't have any troubles. But when I send this on Microsoft Exchange I have this structure from IMAP:
stdClass Object
(
[type] => 1
[encoding] => 0
[ifsubtype] => 1
[subtype] => SIGNED
[ifdescription] => 0
[ifid] => 0
[bytes] => -1
[ifdisposition] => 0
[ifdparameters] => 0
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => protocol
[value] => application/pkcs7-signature
)
[1] => stdClass Object
(
[attribute] => micalg
[value] => sha1
)
[2] => stdClass Object
(
[attribute] => boundary
[value] => ----34EFCEA0D98F83964735A9A256302F5D
)
)
[parts] => Array
(
)
)
As you can see, I don't have parts, and my question is, why I don't recived this element of IMAP structure?
Additionally, when I print imap_body, I can see what is in email.
I don't have access to Microsoft server, anyone have something like this?

php imap class is very buggy, when I wrote my email system, i got very big amount of bugs. There is workaround, you have to search it. Try to use some imap_class.php open source.

Related

How can I get a specific value in this PHP array?

I'm setting up a Cloudinary listing of uploaded videos and I want to get the metadata of that video.
I have a print_r($result):
<pre>
Cloudinary\Api\Response Object
(
[rate_limit_reset_at] => 123123123
[rate_limit_allowed] => 123
[rate_limit_remaining] => 123
[storage:ArrayObject:private] => Array
(
[public_id] => dog
[format] => mp4
[version] => 123123123
[resource_type] => video
[type] => upload
[created_at] => 2019-07-29T07:32:50Z
[bytes] => 123123
[width] => 321
[height] => 456
[backup] => 1
[access_mode] => public
[url] => http://res.cloudinary.com/demo/video/upload/dog.mp4
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.mp4
[next_cursor] => 123123123
[derived] => Array
(
[0] => Array
(
[transformation] => /jpg
[format] => jpg
[bytes] => 86438
[id] => 123123123
[url] => http://res.cloudinary.com//demo/video/upload/dog.jpg
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.mp4
[extension] => jpg
)
[1] => Array
(
[transformation] => t_media_lib_thumb/jpg
[format] => jpg
[bytes] => 3293
[id] => 12123123
[url] => https://res.cloudinary.com/demo/video/upload/dog.jpg
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.jpg
[extension] => jpg
)
)
)
)
</pre>
I tried getting the value using this format but it says undefined index. echo $result[4]['width'] or echo $result['storage:ArrayObject:private']['width'];
I talked to a cloudinary support ad he said that "you should be able to access the data returned within [storage:ArrayObject:private] by simply ignoring it and requesting the index that you desire directly from $result. Meaning you can use or and so on with the other paramters."
So basically, just removing the index solved my problem like so:
<?php echo $result['height']; ?> <?php echo $result['width']; ?>
Have a look at this https://github.com/cloudinary/cloudinary_php/blob/master/src/Api/Response.php in order to better understand the object you are getting back.
Afterwards, look at the ArrayObject documentation here https://www.php.net/manual/en/class.arrayobject.php, as your Response object extends this class. Using getArrayCopy() to transform your object into an array should be what you need.
Bear in mind that I am not familiar with the API and that there may be better options to get what you need.

PHP Imap: which unique identifier should i use?

Im in the meddle of creating a web app that downloads all the emails using imap library in php but im troubled on which id should i used, This is a sample email header retrieve from a gmail account.
Array
(
[0] => stdClass Object
(
[subject] => test subject
[from] => someone
[to] => enquire#xxxx.com
[date] => 17 Jun 2016 10:33:13 +0900
[message_id] => <08a32A30-C6n7-4A4A-AE91-C35429AF48BA#x2mail.xxxx.com>
[size] => 8460
[uid] => 8645
[msgno] => 8522
[recent] => 0
[flagged] => 0
[answered] => 0
[deleted] => 0
[seen] => 0
[draft] => 0
[udate] => 1466127256
)
)
as you can see above there is a "uid" and "msgno" which should i use?
http://php.net/manual/en/function.imap-uid.php
Here I read: An UID is a unique identifier that will not change over time while a message sequence number may change whenever the content of the mailbox changes.
So, "uid" would probably be better.

cakephp ldap login with idbroker plugin

I am blocked with a strange problem. I have added a connection with auth to my application. This is a ldap connection, to do this is use the idbroker plugin from analogrithems. It works well in the developpement mode (Configure::write('debug', 2); in core.php), but when I put it to 0 the plugin is not able make request to the ldap. I have some error.
The error in the log is
2014-07-11 08:37:28 Ldap.error: Query Params Failed:Array
(
[conditions] => (&(objectclass=group) member=CN=toto,OU=Users,OU=Paris,OU=France,DC=world,DC=local))
[fields] => Array
(
[0] => *
[1] =>
[2] => +
[3] =>
)
[joins] => Array
(
)
[limit] =>
[offset] =>
[order] => Array
(
[0] =>
)
[page] => 1
[group] =>
[callbacks] => 1
[scope] => sub
[type] => search
[targetDn] => DC=world,DC=local
)
Error: Operations error
I try to debug it by myself, but I can't.

Retrieve email address from imap header

I'm using php imap function imap_header to extract full header and imap_fetch_overview to extract raw header. Both the functions gives me stdClass object and arrays respectively.
I would like to always clean my from and to before further processing. Sometimes a FROM or TO can contain some thing like this,
Test user <test#test.com>
Also currently in my FROM I only see Test User and no email address until I use firebug.
How do I just get the test#test.com from these objects, arrays?
This is the result I get from imap_fetch_overview
Array
(
[0] => stdClass Object
(
[subject] => Testing
[from] => Test User
[to] => testuser2#test.com
[date] => Wed, 17 Apr 2013 18:43:46 +0530
[message_id] => <abcdef1244.93784jgsfk#test.com>
[size] => 3443
[uid] => 1234
[msgno] => 123
[recent] => 0
[flagged] => 0
[answered] => 0
[deleted] => 0
[seen] => 0
[draft] => 0
[udate] => 1366204439
)
)
There is a hidden <test#test.com> next to Test User. How do I extract that email address?
Similarly this is what I get from imap_header
stdClass Object
(
[date] => Wed, 17 Apr 2013 18:43:46 +0530
[Date] => Wed, 17 Apr 2013 18:43:46 +0530
[subject] => Test
[Subject] => Test
[message_id] => <abcdef1244.93784jgsfk#test.com>
[toaddress] => testuser#test.com
[to] => Array
(
[0] => stdClass Object
(
[mailbox] => testuser
[host] => test.com
)
)
[fromaddress] => Test User
[from] => Array
(
[0] => stdClass Object
(
[personal] => Test User
[mailbox] => test
[host] => test.com
)
)
[reply_toaddress] => Test User
[reply_to] => Array
(
[0] => stdClass Object
(
[personal] => Test User
[mailbox] => test
[host] => test.com
)
)
[senderaddress] => Test User
[sender] => Array
(
[0] => stdClass Object
(
[personal] => Test User
[mailbox] => test
[host] => test.com
)
)
[Recent] =>
[Unseen] => U
[Flagged] =>
[Answered] =>
[Deleted] =>
[Draft] =>
[Msgno] => 123
[MailDate] => 17-Apr-2013 13:13:59 +0000
[Size] => 3443
[udate] => 1366204439
)
A preg_match would be the obvious answer but just cant seem to figure out how to perform it on from bit where email address is not seen in the browser but is present when inspected with firebug. Any help is appreciated.
Thanks.
You can go one step further with imap_rfc822_parse_adrlist()Docs:
$toAddresses = imap_rfc822_parse_adrlist('Test user <test#test.com>', 'localhost');
print_r($toAddresses);
Array
(
[0] => stdClass Object
(
[mailbox] => test
[host] => test.com
[personal] => Test user
)
)
If name of array of std object is $arr
$arr[0]->to
returns what you want.
in second case
$stdObject <- object that is returned by second function
foreach($stdObject->to as $to)
{
echo $to->mailbox;
echo $to->host;
}
I've just discovered this thread and whilst it's old I hope this comment might help. I believe I've answered the query. As it happens, the format of the sender email is what's causing the issue.
From Name <from#name.com>
Because of the <> tag, the browser is making it into an HTML tag, I guess something akin to a span. By using str_replace to change "<" into " " (or whatever) you remove the issue before it gets to HTML

How to find out Yahoo email address using Yahoo API PHP

so heres my predicament.
Currently using Yahoo API with PHP in order to use a 'Login with Yahoo' Function on my site.
I have managed to retrieve my entire profile. Trouble is, I can't directly display the primary email associated with the account.
If I use print_r($profile) I get everything dumped from my profile. It looks like this (personal data removed):
stdClass Object ( [uri] => http://social.yahooapis.com/v1/user/*********/profile [guid] => ***** [birthdate] => / [created] => 2010-04-22T20:47:48Z [emails] => Array ( [0] => stdClass Object ( [handle] => **#gmail.com [id] => 1 [type] => HOME ) [1] => stdClass Object ( [handle] => ****#yahoo.com [id] => 2 [primary] => 1 [type] => HOME ) ) [familyName] => Surname [gender] => M [givenName] => Ricki [image] => stdClass Object ( [height] => 192 [imageUrl] => http://l.yimg.com/dh/ap/social/profile/profile_b192.png [size] => 192x192 [width] => 192 ) [lang] => en-US [memberSince] => 2010-04-08T11:22:56Z [nickname] => Ricki [profileUrl] => http://profile.yahoo.com/*********** [updated] => 2013-03-03T18:12:22Z [isConnected] => )
Using $profile->emails->handle yields nothing however. Any ideas on what to do? I can use $profile->emails which returns an Array, displayed simply as 'Array' but if i try to select from the array i get an error:
"Catchable fatal error: Object of class stdClass could not be converted to string"
Anyone?
$profile->emails[0]->handle will give you the first handle in the system.
You can also do foreach($profile->emails as $email) { print $email->handle; }

Categories