HORDE Imap PHP client - how to fetch messages - php

Okay, had no luck with the ZETA email client, so now I tried installing the Horde IMAP Client library. I've managed to login to my account, and make a search for e-mails, also got back the results, but I don't know how to fetch the email data, and the documentation is not really helping:|
I presume that I would have to use the Horde_Imap_Client_Base::fetch() method to get some e-mails, which accepts two parameters, a mailbox name, and a Horde_Imap_Client_Fetch_Query object, but I don't know how to get this second object:|
Should this object be returned by one of the Base functions, or should I build this object with the query parameters I want? If the second, how should I rebuild my search query in the fetch query object from the below example?
Here's how I am searching my INBOX, for mails from a specific contact on a specific day:
$client = new Horde_Imap_Client_Socket(array(
'username' => 'my.email#address.com',
'password' => 'xxxxxxxxxx',
'hostspec' => 'my.mail.server',
'port' => '143',
'debug' => '/tmp/foo',
));
$query = new Horde_Imap_Client_Fetch_Query();
$query->dateSearch(new Date(), Horde_Imap_Client_Search_Query::DATE_ON);
$query->headerText("from","mycontact#contact.email");
$results = $client->search('INBOX', $query);
The Horde_Imap_Client_Base::search() returns an array, which contains the search results(the message id's of the searched emails), and some additional data.

Not completely answering your questions. This is how I search for messages which are not deleted.
$client = new Horde_Imap_Client_Socket(array(
'username' => $user,
'password' => $pass,
'hostspec' => $server,
'secure' => 'ssl'
));
$query = new Horde_Imap_Client_Search_Query();
$query->flag(Horde_Imap_Client::FLAG_DELETED, false);
$results = $client->search('INBOX', $query);
foreach($results['match'] as $match) {
$muid = new Horde_Imap_Client_Ids($match);
$fetchQuery = new Horde_Imap_Client_Fetch_Query();
$fetchQuery->imapDate();
$list = $client->fetch('INBOX', $fetchQuery, array(
'ids' => $muid
));
var_dump($list);
}

$results = $client->search($mailbox, $searchquery, array('sort' => array($sSortDir, $sSort)));
$uids = $results['match'];
for ($i = $i_start; $i < $i_to; $i++)
{
$muid = new Horde_Imap_Client_Ids($uids->ids[$i]);
$list = $client->fetch($mailbox, $query, array(
'ids' => $muid
));
$flags = $list->first()->getFlags();
$part = $list->first()->getStructure();
$map = $part->ContentTypeMap();
$envelope = $list->first()->getEnvelope();
}

Related

How to get collection class object from mongodb/driver/manager in PHP

I am using the (current? not sure, php documentation is very opaque to me) method to connect to a MongoDB from PHP:
$manager = new MongoDB\Driver\Manager("mongodb://{$user}:{$pwd}#{$url}", array("ssl" => true), array("context" => $ctx));
From there, if I want to write something I do the following:
$bson = MongoDB\BSON\fromJSON($newData);
$value = MongoDB\BSON\toPHP($bson);
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->update(
$filter,
['$set' => $value],
['multi' => false, 'upsert' => $upsert]
);
$results = $manager->executeBulkWrite("$DB.$collection", $bulk);
var_dump($results);
All the documentation on the MongoDB PHP tutorials starts with a $collection object... and the functions thereafter seem much more user-friendly (getInsertedID... insertOne...find...findOne...etc).
For example:
<?php
$collection = (new MongoDB\Client)->test->users;
$insertManyResult = $collection->insertMany([
[
'username' => 'admin',
'email' => 'admin#example.com',
'name' => 'Admin User',
],
[
'username' => 'test',
'email' => 'test#example.com',
'name' => 'Test User',
],
]);
printf("Inserted %d document(s)\n", $insertManyResult->getInsertedCount());
var_dump($insertManyResult->getInsertedIds());
It is not clear to me, how they are actually connecting to the DB... how would I go from the $manager connection to a $collection?
On the MongoDB PHP documentation page, it says 'You can construct collections directly using the driver’s MongoDB\Driver\Manager class'. Unfortunately, a search on the resulting page doesn't include the word 'collection' other than as a side comment in a user contributed note'
Elsewhere on the MongoDB PHP reference pages, I see nowhere that the MongoDB\Manager class is described.
So, how do I get access to the many features in the MongoDB\Collection class?
I was not able to get a collection out of the Manager class, however, I was able to use the bulkWrite class to execute an insert in a secure fashion (I believe). I expect the same pattern will work for reads and updates as well.
Code snippet for those that come here after me:
//echo "Specify the cert...";
$SSL_DIR = ".";
$SSL_FILE = "XXXXXX.pem";
$ctx = stream_context_create(array(
"ssl" => array(
"cafile" => $SSL_DIR . "/" . $SSL_FILE,
))
);
//echo "Done\n";
// echo "Creating manager...";
$manager = new MongoDB\Driver\Manager("mongodb://{$user}:{$pwd}#{$url}", array("ssl" => true), array("context" => $ctx));
// echo "Done!\n";
// echo "Making BSON...";
$bson = MongoDB\BSON\fromJSON($newData);
// echo "Done!\nMaking Value...";
$value = MongoDB\BSON\toPHP($bson);
$value->_id = (string) new MongoDB\BSON\ObjectID;
// echo "Done!\nMaking Bulk...";
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert($value);
// echo "Done!\nExecuting Bulk Write";
$results = $manager->executeBulkWrite("$db.$collection", $bulk);
if($results->getInsertedCount()==1) {
echo $value->_id;
} else {
echo $results->getWriteErrors();
}
// echo "Done!\n";

WSDL authentication

I am first time working with WSDL (no matter which coding language) and I am trying to call one api from it.
I have wsdl specification
https://testsportmidoffice.iedu.sk/Services/Sys/Codebook.svc?singleWsdl
I have username and password
And I have tried it multiple times, one of the tries:
$wsdl_codebook = "https://testsportmidoffice.iedu.sk/Services/Sys/Codebook.svc?singleWsdl";
$client_codebook = new SoapClient($wsdl_codebook, array("trace" => 1));
$header = new SoapHeader('http://tempuri.org/', 'AuthHeader', array('Login' => $auth_login, 'Password' => $auth_password));
$client_codebook->__setSoapHeaders($header);
$sportListParam = array (
'LanguageID' => 'sk'
);
$result = $client_codebook->__soapCall("GetSportList", $sportListParam);
Can someone help me why it's not working? Seems that this is an issue with authentication

Facebook API Get Ad Account Ad Spend

I'm attempting to just get the spend for specific Ad Accounts from the previous day. Whenever I send up the request:
$api = Api::instance();
$account = new AdAccount('act_<account_id>');
$params = array(
'level' => 'account',
'date_preset' => 'yesterday',
'fields' => ['spend', 'account_id'],
);
$insights = $account->getInsights(array(), $params);
print_r($insights);
I get a large protected object back and can't seem to find any documentation as to how to access the actual requested data.
//Get HLG Ad Spend
$account = new AdAccount('act_10153795481711178');
$params = array(
'level' => 'account',
'date_preset' => 'yesterday',
'fields' => ['spend', 'account_id']
);
$insights = $account->getInsights(array(), $params);
$hlgData = $insights->getResponse()->getContent()['data'];
if(isset($hlgData[0]))
{
$hlgSpendFB = $hlgData[0]['spend'];
}else{
$hlgSpendFB = "0";
}
Above is how I was able to get the data from the Ad Account for spend from previous day. After digging through the object itself I was able to find the getter functions that procured the data requested.

Mailchimp intergration error

We want to import all our database into one of your lists. We use php. The code is:
$api_key = "dXXXXXXX7eX276XXXXXXXX490";
$list_id = "7XXXb0XXXe";
$Mailchimp = new Mailchimp($api_key);
$Mailchimp_Lists = new Mailchimp_Lists($Mailchimp);
$batch = array();
$batch[] = array('email' => array(
'email' => 'xxxgmail.com',
"euid" => "xxx#gmail.com",
"leid" => "xxx#gmail.com"
),
'merge_vars' => array('FNAME' => 'XXX'));
$subscriber = $Mailchimp_Lists->batchSubscribe($list_id, $batch, false, true, true);
But I get an error
Mailchimp_User_DoesNotExist
Could not find user record with id
I tried many times, removed uuid and leid but no success. What is wrong? Thank you!
The API key used by me was incorrect.

OData PHP Producer

I need to create a PHP OData producer supporting both GET and PUT. Up to now I've only found this library, unfortunately this not support PUT operation.
Any suggestions?
Thank's
Currently there's no PHP Library (public) available to support OData CUD (Change, Update and Delete) operations.
Just released. Documentation is coming.
https://packagist.org/packages/falseclock/dbd-php
$cache = DBD\Cache\MemCache::me()->create(array(['host' => '127.0.0.1', 'port' => 11211]),false,"15 min")->open();
$odata_options = array(
'RaiseError' => true,
'PrintError' => true,
'HTMLError' => true,
'CacheDriver' => $cache
);
$od = (new DBD\OData())->create('http://crm.beta.virtex.kz/odata/', "user", "password", $odata_options);
$sth = $od->prepare("
SELECT
Ref_Key, Number, Date
FROM
Document_Invoices
ORDER BY
Date аsc
LIMIT 10
");
$sth->cache('CacheKey','24h');
$sth->execute();
while ($row = $sth->fetchrow()) {
print_r($row);
}
$od->update(
'Document_Invoices',
array('Date' => $data['Date']),
"(guid?)",
$data['Ref_Key'] // for ?-placeholder
);

Categories