Identifying attachments in WEBDav result - php

Using the WEBDav libraries from Troy Wolf
I am using the following query to pull results from the Exchange Server
$search = <<<END
<?xml version="1.0"?><a:searchrequest xmlns:a="DAV:" xmlns:s="http://schemas.microsoft.com/exchange/security/">
<a:sql>SELECT "DAV:displayname",
"urn:schemas:httpmail:from",
"urn:schemas:httpmail:subject",
"urn:schemas:httpmail:textdescription",
"urn:schemas:httpmail:htmldescription",
"urn:schemas:httpmail:hasattachment",
"urn:schemas:httpmail:attachmentfilename",
"urn:schemas:httpmail:sender" FROM "$mailbox" WHERE "DAV:isfolder"=False AND "http://schemas.microsoft.com/exchange/outlookmessageclass"='IPM.NOTE'</a:sql>
</a:searchrequest>
END
This works however the return comes back as
array
0 =>
object(stdClass)[10]
public '_attr' =>
object(stdClass)[11]
public 'A_STATUS' =>
array
0 =>
object(stdClass)[12]
public '_attr' =>
object(stdClass)[13]
...
public '_text' => string 'HTTP/1.1 200 OK' (length=15)
public 'A_PROP' =>
array
0 =>
object(stdClass)[14]
public '_attr' =>
object(stdClass)[15]
...
public 'A_DISPLAYNAME' =>
array
...
public 'D_FROM' =>
array
...
public 'D_SUBJECT' =>
array
...
public 'D_TEXTDESCRIPTION' =>
array
...
public 'D_HTMLDESCRIPTION' =>
array
...
public 'D_HASATTACHMENT' =>
array
...
1 =>
object(stdClass)[28]
public '_attr' =>
object(stdClass)[29]
public 'A_STATUS' =>
array
0 =>
object(stdClass)[30]
public '_attr' =>
object(stdClass)[31]
...
public '_text' => string 'HTTP/1.1 404 Resource Not Found' (length=31)
public 'A_PROP' =>
array
0 =>
object(stdClass)[32]
public '_attr' =>
object(stdClass)[33]
...
public 'D_ATTACHMENTFILENAME' =>
array
...
public 'D_SENDER' =>
array
...
Whether a file is attached or not, D_ATTACHMENTFILENAME is returned with a 404. Any ideas why?
tl;dr - cannot retrieve list of attached files for emails through a webdav service.

You can't get the filenames of the attachments using a Search request. Instead, filter on items which have the hasattachment set to 1. Foreach each of those elements, issue an X-MS-ENUMATTS request to get the attachment properties.

Related

Get behavior related configuration from code

Are behavior related configurations accessible? In this specific case, a behavior was attached to a table. I would like to know if it's possible to get the fields property in some way, later on in code?
<?php
class MyRandomTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
...
// Add Cipher behavior
$this->addBehavior('CipherBehavior.Cipher', [
'fields' => [
'original' => 'string',
'changed' => 'string',
]
]);
}
...
}
?>
If I load the table and dump the content, I do not see the behavior listed:
$table = TableRegistry::get('MyRandomTable');
var_dump($table);
Partial dump content:
protected '_behaviors' =>
object(Cake\ORM\BehaviorRegistry)[170]
protected '_table' =>
&object(Cake\ORM\Table)[172]
protected '_methodMap' =>
array (size=0)
empty
protected '_finderMap' =>
array (size=0)
empty
protected '_loaded' =>
array (size=0)
empty
protected '_eventManager' =>
object(Cake\Event\EventManager)[165]
protected '_listeners' =>
array (size=0)
...
protected '_isGlobal' => boolean false
protected '_eventList' => null
protected '_trackEvents' => boolean false
protected '_eventClass' => string '\Cake\Event\Event' (length=17)
What I'd like to do, in a controller, is to get the fields and pass those on to a view.
Edit #1
Using CakePHP v3.3.16
Edit #2
I'm seeing behavior information as I had missed the plugin prefix when loading the table:
$table = TableRegistry::get('PluginName.MyRandomTable');
Shows:
protected '_behaviors' =>
object(Cake\ORM\BehaviorRegistry)[143]
protected '_table' =>
&object(PluginName\Model\Table\MyRandomTable)[94]
protected '_methodMap' =>
array (size=4)
'timestamp' =>
array (size=2)
...
'touch' =>
array (size=2)
...
'encrypt' =>
array (size=2)
...
'decrypt' =>
array (size=2)
...
protected '_finderMap' =>
array (size=0)
empty
protected '_loaded' =>
array (size=2)
'Timestamp' =>
object(Cake\ORM\Behavior\TimestampBehavior)[181]
...
'Cipher' =>
object(CipherBehavior\Model\Behavior\CipherBehavior)[192]
...
protected '_eventManager' =>
object(Cake\Event\EventManager)[175]
protected '_listeners' =>
array (size=4)
...
protected '_isGlobal' => boolean false
protected '_eventList' => null
protected '_trackEvents' => boolean false
protected '_eventClass' => string '\Cake\Event\Event' (length=17)
First of all your table class file is incorrect, it needs a namespace, otherwise it cannot be found, and you'll end up with an instance of \Cake\ORM\Table (a so called auto/generic-table) instead of concrete subclass thereof, hence your behavior is missing.
That being said, it depends on how the behavior has been programmed. If it follows the default configuration pattern, then you can access the configuration via its config() or getConfig() (as of CakePHP 3.4) methods.
Of course you have to access the behavior, not just the table class to which it is attached. This is done using the behavior registry, which is available via the Table::behaviors() method:
$fields = $table->behaviors()->get('Cipher')->config('fields');
See also
Cookbook > Database Access & ORM > Behaviors > Accessing Loaded Behaviors
Cookbook > Database Access & ORM > Behaviors > Re-configuring Loaded Behaviors
API > \Cake\ORM\BehaviorRegistry
API > \Cake\ORM\Behavior
Cookbook > Configuration > Disabling Generic Tables
You can get Column names of a table by schema()->columns().
Example -
$getColumnArray = $this->Users->schema()->columns();//return Users Table Colums Name Array
$getColumnArray = $this->Users->associations()->keys()//return Users assocation table key

Autoload and use simple HTML dom external librarie in Codeigniter 3.0.1

I'm having problems with including / using external libraries in CodeIgniter 3.0. So this is what i did so far:
I have placed simple_html_dom.php file in my application/libraries folder
Then i'm auto loading it with this line of code in
/*
example of CI
$autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array('simple_html_dom' => 'shd');
And this is my controller
public function index()
{
$html = $this->shd->str_get_html('<html><body>Hello!</body></html>');
var_dump($html);
die();
$this->load->view('parser');
}
Which provides me an error of:
A PHP Error was encountered
Severity: Error
Message: Call to undefined method simple_html_dom::str_get_html()
Filename: controllers/Parser.php
Line Number: 8
Documentation of simple_html_dom can be found on this link
To me it looks like librarie gets loaded, but i can't use its functions.
I hope somebody can help. Thank you in advance!
I found a solution. After checking documentation of simple html dom, i found out that you can also use object oriented way. So my controller looks like this now:
$html = new simple_html_dom();
$html->load('<html><body>Hello!</body></html>');
var_dump($html);
And i have result:
object(simple_html_dom)[17]
public 'root' =>
object(simple_html_dom_node)[18]
public 'nodetype' => int 5
public 'tag' => string 'root' (length=4)
public 'attr' =>
array (size=0)
empty
public 'children' =>
array (size=1)
0 =>
object(simple_html_dom_node)[19]
...
public 'nodes' =>
array (size=1)
0 =>
object(simple_html_dom_node)[19]
...
public 'parent' => null
public '_' =>
array (size=2)
0 => int -1
1 => int 4
public 'tag_start' => int 0
private 'dom' =>
&object(simple_html_dom)[17]
public 'nodes' =>
array (size=4)
0 =>
object(simple_html_dom_node)[18]
public 'nodetype' => int 5
public 'tag' => string 'root' (length=4)
public 'attr' =>
array (size=0)
...
public 'children' =>
array (size=1)
...
public 'nodes' =>
array (size=1)
...
public 'parent' => null
public '_' =>
array (size=2)
...
public 'tag_start' => int 0
private 'dom' =>
&object(simple_html_dom)[17]
you can use
$this->load->library("simple_html_dom"); //class name should come here
And make sure simple_html_dom.php class name is simple_html_dom
Try this -
$autoload['libraries'] = array('simple_html_dom');
You can do this like that:
$this->load->library("simple_html_dom");
$this->simple_html_dom->your_method();

Amazon Advertising API get Node's products

I'm creating e-commerce shop with Amazon API integration.
The problem I faced with is I cannot get items from specific node.
So I've tried many ways to do that, last one was something like this:
$fields = array();
$fields['AssociateTag'] = "ItemSearch";
$fields['Condition'] = 'All';
$fields['Operation'] = 'ItemSearch';
$fields['Version'] = '2013-08-01';
$fields['BrowseNode'] = $catId;
$fields['ResponseGroup'] = "Images,ItemAttributes,Offers";
$fields['Service'] = 'AWSECommerceService';
$fields['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
$fields['AWSAccessKeyId'] = $this->accessKey;
After that call I have the output:
public 'Items' =>
object(SimpleXMLElement)[150]
public 'Request' =>
object(SimpleXMLElement)[139]
public 'IsValid' => string 'True' (length=4)
public 'ItemSearchRequest' =>
object(SimpleXMLElement)[138]
public 'BrowseNode' => string '1289481011' (length=10)
public 'Condition' => string 'All' (length=3)
public 'ResponseGroup' =>
array (size=3)
0 => string 'Images' (length=6)
1 => string 'ItemAttributes' (length=14)
2 => string 'Offers' (length=6)
So I can see my request, but no items were returned to me.
By the way, ItemLookup, ItemSearch with keywords and BrowseNode operations work just fine.
What can I do to get items from node with spicific ID without using keywords?
I figured out what happened. I didn't set SearchIndex when I point BrowseNode ID.
So there was no result.

MailChimp API listStaticSegments is always empty

I have created several static Segments in Mailchimp for a List.
I am writing some PHP to create campaigns, but I am stuck on a hurdle early on.
I am using v1.3 of the MailChimp API
$api = new MCAPI( $this->config['api_key'] );
$lists = $api->listStaticSegments( $list_id );
var_dump( $api );
var_dump( $lists );
Results:
object(MCAPI)[39]
public 'version' => string '1.3' (length=3)
public 'errorMessage' => string '' (length=0)
public 'errorCode' => string '' (length=0)
public 'apiUrl' =>
array (size=4)
'scheme' => string 'http' (length=4)
'host' => string 'api.mailchimp.com' (length=17)
'path' => string '/1.3/' (length=5)
'query' => string 'output=php' (length=10)
public 'timeout' => int 300
public 'chunkSize' => int 8192
public 'api_key' => string 'XXX' (length=XX)
public 'secure' => boolean false
array (size=0)
empty
I am expecting $lists to have 10 items in an array.
When I log into MailChimp and check the API Account API Keys page, I can see there are requests but there are no responses.
Ah ha. The problem was I had no static lists. The lists that I had created were dynamic segments (auto updating) , so therefore I must use campaignSegmentTest to generate the same criteria for the dynamic segments.
http://apidocs.mailchimp.com/api/1.3/campaignsegmenttest.func.php
Further research on the Google Mailchimp forum:
https://groups.google.com/forum/#!msg/mailchimp-api-discuss/63DLfYq7ydI/jyGASmUxK8AJ

Amazon PHP SDK Listing Objects

I have the need to display the bucket contents on my S3 and I am using Amazon's PHP SDK.
My code is simply
$objects = $s3->list_objects("mybucket",array("max-keys"=>5));
var_dump($objects);
The response I get from the server is very complicated for me to understand -
It's essence is
Object(CFResponse)[107]
public 'header' =>
array (size=11)
'x-amz-id-2' => string
...
public 'body' =>
object(CFSimpleXML)[106]
public '#attributes' =>
array (size=1)
'ns' => string 'http://s3.amazonaws.com/doc/2006-03-01/' (length=39)
public 'Name' => string 'cdneu.2yourfacecdn.com' (length=22)
public 'Prefix' =>
object(CFSimpleXML)[3]
public 'Marker' =>
object(CFSimpleXML)[105]
public 'MaxKeys' => string '5' (length=1)
public 'IsTruncated' => string 'true' (length=4)
public 'Contents' =>
array (size=5)
0 =>
object(CFSimpleXML)[104]
...
1 =>
object(CFSimpleXML)[103]
...
2 =>
object(CFSimpleXML)[102]
...
3 =>
object(CFSimpleXML)[101]
...
4 =>
object(CFSimpleXML)[100]
...
public 'status' => int 200
I believe the part under the 'Contents' is what I'm looking for but how do I access it ? I'm used to receiving arrays where I can figure out what the keys are and how to access but this here is difficult for me ,
Any guesses?
try this in order to list the key element of each object:
$s3 = new AmazonS3();
$objects = $s3->list_objects("YOUR BUCKET NAME",array("max-keys"=>5));
foreach ($objects->body->Contents as $item){
print_r($item->Key."");
}
You can access contents as follows
$contents = $objects['Contents'];

Categories