IMAP array values changing spontaneously - PHP - gmail

My company uses script-generated emails to correspond with clients. Until now, we've had to manually sort through these emails, look up client info, print and file them. I'm writing a script that does this automatically and it was working fine until 10 minutes ago when Google stopped sending the subject with imap_fetch_overview().
Here's how I'm doing it:
$msgov=imap_fetch_overview($inbox,$uid,FT_UID);
$msgsub= $msgov[0]->subject;
$msgfr= $msgov[0]->from;
$msgid= $msgov[0]->uid;
$message = imap_fetchbody($inbox,$uid,1,FT_UID);
//echo message info, then message
echo "...";
And that worked fine until about 10 minutes ago when I started getting this error: Notice: Undefined property: stdClass::$subject in C:\wamp\www\gmil\index.php on line 113
So I proceed to echo var_dump($msgov); and suddenly it's not showing the subject anymore.. According to The Manual it should be giving me the subject. Am I doing something wrong or am I just unlucky enough to be doing this at the exact time Google decided to stop sending it?

I'm dumb.
After one message not didn't contain a subject, it stopped checking for that value in all subsequent loops. I solved it like this:
if(isset($overview[0]->subject)){$sub=$overview[0]->subject;}else{$sub="No Subject";}
and then called $sub instead of $overview[0]->subject.

Related

^HV Only returning some values

I'm trying to print some RFID tags and retrieve their TIDs to store them in my system and know which tags have been printed. Right now I'm reading the TID and sending it back to my computer (connected via USB with the my ZT421 printer) with the following code:
^RFR,H,0,12,2^FN0^FS^FH_^HV0,24,,_0D_0A,L^FS
^RFW,H,2,12,1^FD17171999ABABABAAAAAAAAAB^FS
This is repeated for each tag that I'm printing. However, when printing 10 tags, I only get 9 TIDs. If after that I try to print 7 tags, I still get 9 TIDs. To be honest I'm a bit lost now, because even trying to use the code examples from the ZPL manual (I've tried the ^RI instruction also) it doesn't seem to work.
The communication with the printer is beeing done through Zebra Setup Utilities' direct communication tool.
I tried to retrieve each printed tag TID with:
^RFR,H,0,12,2^FN0^FS^FH_^HV0,24,,_0D_0A,L^FS
^RFW,H,2,12,1^FD17171999ABABABAAAAAAAAAB^FS
but I always get 9 TIDs.
I also tried getting the TID with the ZPL manual example for the ^RI command:
^XA
^FO20,120^A0N,60^FN0^FS
^RI0,,5^FS
^HV0,,Tag ID:^FS
^XZ
And I got absolutely nothing returned to the computer, just a mssage saying "Tag ID:" and no value shown.
I would really appreciate some help with this...
Thanks in advance!
I've fixed the issue, but I'm going to leave the solution here just in case someone else is facing the same problem.
I thought that maybe it wasn't a code issue, but something related to the computer-printer communication. It turned out to be the case. The Zebra Setup Utilities program has a button that says "options". If you click it, a new screen will open and there you can configure the seconds that the program will wait for the printer response (in this case through USB). By default it's set to 5, i changed this value to 100, which is the maximum. This meant that instead of just printing and retrieving the TIDs of 6-9 tags, now I can do it for about 100.
This is not amazing because in my case it implied creating 25 files for the 2500 tags I had to print and store the TIDs, however it's far better than before.

tailLines and SinceTime in logging api,both not worked simultaneously

I am using container engine, and my pods are hosted there.
I am trying to fetch logs, using log api :
http://localhost:8000/api/v1/namespaces/app-test/pods/designer-0/log?tailLines=100&sinceTime=2017-09-17T10:47:58Z
if i used both the query params separately, it works and show the proper result, but if i am using it simultaneously only the top 100 logs are returning, the sinceTime param is get ignored.
my scenario is, i need a log from a specific time, in a chunk like, 100 lines, 100 lines.. like this.
I am not sure, whether it is a bug, or it is not implemented.
I found this from the api reference manual
https://kubernetes.io/docs/api-reference/v1.6/
tailLines - If set, the number of lines from the end of the logs to
show. If not specified, logs are shown from the creation of the
container or sinceSeconds or sinceTime
So, that means if you specify tailLines, it start from the end. I dont see any option explicitly mentioned other than limitBytes. But you will have to play around with it as it does not guarantee number of lines.
tailLines=X tells the server to start that many lines from the end
sinceTime tells the server to start from the specified time
the options are mutually exclusive
Thanks All,
I have later on recognized that, it is not ignoring the sinceTime, as the TailLines intended functionality is return the lines from the last.
So, if i mentioned the sinceTime= 10 PM yesterday, it will return the records from that time..And if also tailLines, is mentioned, so it will return the recent logs from that chunk.
So, it was working as expected. I need to play with LimitBytes for getting the logs in chunk, from that time, Instead of full logs.

Perl: Read email and use message content as stdin for an excel update

I am looking for some help with starting a Perl script. I'm relatively inexperienced with Perl so help would be appreciated :)
Basically, want to start a project to write a script that helps keep up to date with hours I have been working. Basically I would like the script to E-mail (automated using cron) me reminding me to send my hours each day, then I send an e-mail back with the message as something like
"03/02/14 7.30 18.30"
The script will then read the data and update an excel spreadsheet keeping a log of hours.
I know how to do everything except having the script read an e-mail. I have been doing research into MIME::* MAIL::* but I'm not entirely sure which package would be the best and how to actually go about it.
As #mpapec suggested you could read email using IMAP or a local mailbox on a linux box.
In windows you could use OLE and read emails in an outlook: Perl: Win32::OLE and Microsoft Outlook - Iterating through email attachments efficiently
You could read emails on exchange in this way: http://metacpan.org/pod/Email::Folder::Exchange
If I were you I would use IMAP to access emails. It is platform independent and not too hard to use (I used it in the past and it was reliable).
http://metacpan.org/pod/Net::IMAP::Client
my $imap = Net::IMAP::Client->new(
server => 'mail.you.com',
user => 'USERID',
pass => 'PASSWORD');
# select folder
$imap->select('INBOX');
#newest first
my $messages = $imap->search({
FROM => 'you',
SUBJECT => 'your email subjet',
}, [ '^DATE' ]);
# fetch full message (newest)
my $data = $imap->get_rfc822_body($messages->[0]);
#process
store_data_in_excel($data);
#move to archive
$imap->copy([$messages->[0]], 'Archive');
$imap->add_flags(\#msg_ids, '\\Deleted');
$imap->expunge;

Nlog - email logs every x minutes

Is it possible to email logs every x minutes using NLog?. if so, are there any examples.
thanks.
I doubt It, If I was you I would only email Logs of Error or Fatal level, if you what to email at specific times, just create a simple timer that emails the ErrorLog.txt File every x minutes.

Reading emails with groovy (Java Mail)

I am using groovy in order to access gmail and read the Inbox. It is regular JavaMail and will not describe it here.
So for simplicity, after I connect to the store, I use this:
folder.open(Folder.READ_ONLY)
folder.messages.each { msg ->
...
doSomething with msg
...
}
this is working fine.
However I have a performance issue. Sometimes messages[] could be big. Some folders contain more than 1000 messages, and checking them all takes time.
I am looking for a quicker way to get only those emails that are the most recent (for example messages from the last 5 days or something like that)
of course I have the date information in each msg and I could do my comparison, but this is not efficient since it will loop through the entire collection.
Is there a better way to get those messages?
If you have JavaMail issue a SEARCH command with the criterion SINCE 04-JAN-2011, you'll get back the set messages in the currently-selected folder delivered since January 4th. (SENTSINCE 04-JAN-2011 will do the same thing, only based on the "Date" message header.)
Something along the lines of this:
folder.search(new ReceivedDateTerm(ComparisonTerm.GE, sinceDate));

Resources