cakephp email plugin to pull email by imap - email

I am using this cakephp email plugin to pull the emails from the account. Here are my parameters
'datasource' => 'Emails.Imap',
'server' => 'mail.example.com',
'connect' => 'imap/novalidate-cert',
'username' => 'username',
'password' => 'password',
'port' => '143',
'ssl' => false,
'encoding' => 'UTF-8',
'error_handler' => 'php',
and I make a query as it is indicated in documentation
$ticketEmails = $this->TicketEmail->find('first', array('recursive' => -1));
but when I debug the result, the following fields show data like this
Array
(
[TicketEmail] => Array
(
. . . other fields
[body] => CjxIVE1MPjxCT0RZPnNvbWUgbWVzc2FnZTxicj48L0JPRFk+PC9IVE1MPgo=
[plainmsg] => IHNvbWUgbWVzc2FnZQo=
. . . other fields
)
)
I can not understand why it shows these strings, e.g. in email account's message's body is just this text some message.
My cake version is 1.3
Thanks !

That's Base64 encoding, looks like the plugin doesn't handle that, it only checks for the quoted-printable format.
You could decode the data in your model, for example in the Model::afterFind() callback or in a custom method, or you could try modifying the plugin so that it returns the decoded data (untested):
protected function _fetchPart ($Part) {
$data = imap_fetchbody($this->Stream, $Part->uid, $Part->path, FT_UID | FT_PEEK);
if ($data) {
// remove the attachment check to decode them too
if ($Part->format === 'base64' && $Part->is_attachment === false) {
return base64_decode($data);
}
if ($Part->format === 'quoted-printable') {
return quoted_printable_decode($data);
}
}
return $data;
}

Related

Perl MIME::Lite nested boundaries

I am working on a server that is missing MANY Perl libraries, so I am left with using MIME::Lite. Yes, I should be using something else, but it is not within my control.
Overall, the email package needs to be "multipart/mixed". It will have the plain text version, html version, and an attachment. The issue is, it shows BOTH the plain text and html version in the email body.
I would like to still support "multipart/alternative" so it shows EITHER plain text or html. However, since I need an attachment, the whole email should be "multipart/mixed" with an inner boundary section with "multipart/alternative" for text/html versions.
I though I had it working, but it drops off the attachment due to the whole email package was "multipart/alternative". Inspecting some emails in my inbox, and I noticed you can have "mixed" first, then inside have "alternative". Like a div in a div :)
Here is my current code snip (please look for my comments defining the boundary):
my $type = 'multipart/mixed';
sub sendMail {
my($from, $to, $subject, $messageHtml, $messageText, $type, %attachment) = #_;
my $msg = MIME::Lite->new(
From => $from,
To => $to,
Subject => $subject,
Type => $type, # multipart/mixed
);
# -- start new boundary and multipart/alternative
if ( $messageText ne '' ) {
$msg->attach(
Type => 'text/plain; charset=UTF-8',
Encoding => 'quoted-printable',
Data => $messageText,
);
}
if ( $messageHtml ne '' ) {
$msg->attach(
Type => 'text/html; charset=UTF-8',
Encoding => 'quoted-printable',
Data => $messageHtml,
);
}
# -- end new boundary
if ( %attachment ) {
$msg->attach(
Type => $attachment{"type"},
Encoding => 'base64',
Path => $attachment{"path"},
Filename => $attachment{"filename"},
Disposition => 'attachment'
);
}
if ($debugmode) {
my $result = '';
$msg->print($result);
print $result;
exit;
}
if ($msg->send) {
return 1;
}
return 0;
}
I would modify the code to check if both html and plain text were passed. I am well aware, that I don't need alternative if only 1 of them are used.
Again, I need the plain text and html sections, to be inside their own boundary as "multipart/alternative"
You have to first create the message as multipart/mixed. Inside this message you need to create an inner part as multipart/alternative. Onto this inner part you should attach the HTML and text parts. And the attachment should be added to the outer (mixed) part. This could be achieved with code like this:
use strict;
use warnings;
use MIME::Lite;
# main message is multipart/mixed
my $msg = MIME::Lite->new(
From => 'me#example.com',
To => 'you#example.com',
Subject => 'some test message',
Type => 'multipart/mixed'
);
# inner part as multipart/alternative to include both HTML and text
my $alternative = $msg->attach(
Type => 'multipart/alternative',
);
$alternative->attach(
Type => 'text/plain',
Data => 'some TEXT here'
);
$alternative->attach(
Type => 'text/html',
Data => '<b>some HTML here</b>'
);
# attached image goes to main message
$msg->attach(
Type => 'image/gif',
Data => 'GIF89a....'
);
print $msg->as_string;

perl mime::lite attach text file line feed error

my #test = ("Row1", "Row2", "Row3");
my $attch = join("<cr><lf><br>\\n", #test);
$message = MIME::Lite->new(
From => $mailFrom ,
To => $address,
Subject => $title,
Type => 'text/html',
Encoding => '8bit',
Data => $data
);
$message->attach(
Type =>'TEXT',
Data => $attch
);
MIME::Lite->send('smtp', $host, Timeout => 20);
$message->send;
Good Day, i'm trying send a file in a email, but i cant write correct line feed, the code sends a email with a attached file, this attached file contains the next information:
"Row1<cr><lf><br>\nRow2<cr><lf><br>\nRow3"
How i can get:
Row1Row2Row3
In the attached file?
$message->attach(
Type => 'TEXT',
Data => join('', map { "$_\n" } #test),
);

First/Last record is not coming with data in cakephp+mongo

I m using the mongodb plugin
ichikaway/cakephp-mongodb
And cakephp 2.6.1
The data in post collection
link to image
And in cakephp it is showing me like
link to image
Cakephp controller side code:
$params = array(
'fields' => array('title', 'body', 'hoge'),
//'fields' => array('Post.title', ),
//'conditions' => array('title' => 'hehe'),
//'conditions' => array('hoge' => array('$gt' => '10', '$lt' => '34')),
//'order' => array('title' => 1, 'body' => 1),
'order' => array('_id' => "DESC"),
'limit' => 35,
'page' => 1,
);
$results = $this->Post->find('all', $params);
I want to pull each and every data from mongodb but this plugin is not providing me the last data.
I have checked the count that's correct.
Am I correct in assuming that this error only appeared after upgrading the PHP driver to 1.6.0? The CakePHP module uses hasNext() and getNext() in MongodbSource::read(), which will be affected by a bug (PHP-1382) introduced in 1.6.0. A fix has already been merged and should be released as 1.6.1 on 2015-02-05 (tomorrow).
For additional context, see a previous answer on the subject: https://stackoverflow.com/a/28304142/162228
In MongodbSource.php file I have made just simple change
in read function
There was a code
public function read(Model $Model, $query = array(), $recursive = null) {
........
while ($return->hasNext()) {
$mongodata = $return->getNext();
Changed it to
public function read(Model $Model, $query = array(), $recursive = null) {
........
foreach ($return as $data) {
$mongodata = $data;
And yurekaaaa,its working fine.

Attributes exchange using Net::OpenID::Consumer

my $csr = Net::OpenID::Consumer->new(
ua => LWP::UserAgent->new,
consumer_secret => '123456xXx',
required_root => "http://www.myopenidsample.net/",
);
my $openid = "https://me.yahoo.com";
my $claimed_id = $csr->claimed_identity($openid);
if ($claimed_id){
my $check_url = $claimed_id->check_url(
delayed_return => 1,
return_to => "http://www.myopenidsample.net/response.cgi",
trust_root => "http://www.myopenidsample.net/",
);
print $q->redirect($check_url);
}
How do I get attributes such as email, firstName, lastName, and country?
How do I append the following parameters to a URL?
openid.ext1.mode fetch_request
openid.ext1.required country,email,firstname,lastname,language
openid.ext1.type.country http://axschema.org/contact/country/home
openid.ext1.type.email http://axschema.org/contact/email
openid.ext1.type.firstname http://axschema.org/namePerson/first
openid.ext1.type.language http://axschema.org/pref/language
openid.ext1.type.lastname http://axschema.org/namePerson/
openid.ns.ext1 http://openid.net/srv/ax/1.0
You need to add the following code before the call to check_url (the example was tested with Google in order to get only the email):
$claimed_id->set_extension_args(
"http://openid.net/srv/ax/1.0",
{
'mode' => 'fetch_request',
'type.email' => 'http://axschema.org/contact/email',
'required' => 'email',
});
To get the value back in the return, I use:
my $email = $csr->message->get_ext
("http://openid.net/srv/ax/1.0", "value.email");

Zend Framework: Is it possible to override some of the validator error messages, when using built in translator?

I've used validator errors customization example from this answer: https://stackoverflow.com/a/4881030/822947, but I need to override some of translated errors with addValidator() or setMessage()/setMessages(). Examples below doesn't work (seems, built in translator has priority?)... How can I do it?
$field->addValidator ('Alpha', false, array ('messages' => array (Zend_Validate_Alpha::NOT_ALPHA => 'My msg')));
$Alpha = new Zend_Validate_Alpha ();
$Alpha->setDisableTranslator (true);
$Alpha->setMessage ('My msg', Zend_Validate_Alpha::NOT_ALPHA);
$Alpha->setMessages (array (Zend_Validate_Alpha::NOT_ALPHA => 'My msg'));
$field->addValidator ($Alpha);
UPDATE
The problem not in the way I add validator and set messages to it.
My goal is to localize all error messages. But for some form fields I need to add more specific messages.
For example, in my lang/translate.php I have common
Zend_Validate_Alpha::NOT_ALPHA => 'Value contains non alphabetic characters',
but for name field I need more specific
Zend_Validate_Alpha::NOT_ALPHA => 'Field can contain only alphabetic characters and spaces',
The problem is specific message ignored when I enable built in translator. So for example code
$form = new Zend_Form ();
$validator = new Zend_Validate_Alpha ();
$validator->setMessages (array (
Zend_Validate_Alpha::NOT_ALPHA => 'xxx %value% x'
));
$form->addElement ('text', 'digit', array (
'validators' => array (
$validator
)
));
$name = new Zend_Form_Element_Text ('name');
$name->addValidator ('Alpha', true, array (
'allowWhiteSpace' => true,
'messages' => array
(
Zend_Validate_Alpha::NOT_ALPHA => 'my more specific localized msg',
)
));
$form->addElement ($name);
$form->isValid (array (
'digit' => '___',
'name' => '___',
));
Zend_Debug::dump ($form->getMessages ());
when translator disabled, I have
array(2) {
'digit' =>
array(1) {
'notAlpha' =>
string(9) "xxx ___ x"
}
'name' =>
array(1) {
'notAlpha' =>
string(30) "my more specific localized msg"
}
}
when translator enabled, I have messages from lang/translate.php
array(2) {
'digit' =>
array(1) {
'notAlpha' =>
string(104) "common localized msg"
}
'name' =>
array(1) {
'notAlpha' =>
string(104) "common localized msg"
}
}
The problem is that Alpha validator does not support options array in parameters to constructor. You have to set them separatelly.
$form = new Zend_Form ();
$validator = new Zend_Validate_Alpha ();
/* Custom error message */
$validator->setMessages (array (
Zend_Validate_Alpha::NOT_ALPHA => 'xxx %value% x'
));
$form->addElement ('text', 'digit', array (
'validators' => array (
$validator
)
));
$form->isValid (array (
'digit' => '___'
));
Zend_Debug::dump ($form->getMessages ());
Update
The problem is with your translator then.
I have my translator configured like this:
resources.translate.adapter = Array
resources.translate.data = APPLICATION_PATH "/test-translate"
file en.php:
return array (
"notAlpha" => 'my Translated alpha'
);
and it works.