Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Tool to interface with POP3 accounts Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: December 12 2007 at 19:57 | IP Logged Quote onhiatus

While waiting for a propper POP3 plugin I hacked this together (see this article for history. Basically it's a vb app that goes to a specified pop3 mailbox, downloads all the emails it finds, writes a timestamped file containing the found emails, then appends the newly created file name to an index file.

By using Dave's file monitor plug in to monitor the index file (see this article) it should be easy to write a PH macro to read a line from the index file open the specified email file and process each email in the file.

Emails are saved in the format:
       FROM_ADDRESS<ta b>S UBJECT <tab>BODY
All on one line. Before saving the email body is stripped of all white space (CR/LF/tabs/multiple spaces). If the email is a multi-part email the app tries to save only the plain text part.

I'm going to use this to handle remote control via email and sms. It could also be useful if you wanted PH to display a pending email list somewhere.

Screen shot:


Notes:
1. If you are using this for control I'd strongly recommend using a dedicated email account since you'll want to check the "delete mail from server..." checkbox as this app has no concept of a "new" mail - it always just saves everything it can find.
2. There is no security here. The senders email is just pulled from the "FROM:" entry in the mail header - it would be supper easy to fake. I'm going to use this, but that's my informed choice.
3. This does not support "SSL" so it may not work with your server. For example, it will NOT work with gmail.
4. No guarentees this is of any use to you. It works well for me but has not been tested on more than a handful of server or with more than a few email sources. It's probably just worth just what you paid for it.

Let me know if you have any questions / comments!

Thanks, Tony

The app: 2007-12-12_194636_Pop3PowerhomeBridge.zip
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: December 12 2007 at 20:22 | IP Logged Quote onhiatus

Some examples. After running for a bit with the above settings the app had created three files:

The contents of "outputIndex.txt":
    C:\Program Files\PowerHome\mail\mail-128419812085016440.txt
    C:\Program Files\PowerHome\mail\mail-128419816477560238.txt

The contents of "mail-128419812085016440.txt":
    XXX@tmomail.net   set heat on

The only email that was contained was sent from my phone, so no subject. Guess what it does?

Edited by onhiatus - December 14 2007 at 16:59
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
Gadgets
Senior Member
Senior Member
Avatar

Joined: January 28 2008
Location: Canada
Online Status: Offline
Posts: 178
Posted: January 30 2008 at 00:17 | IP Logged Quote Gadgets

Hey onhiatus,

Just thought I'd look at your POP mail app. When trying to run it, I get this:

.NET Framework Initialization Error

C:\windows\Microsoft.NET\Framework\v2.0.5072\mscorwks.dll could not be loaded



__________________
Friends, don't let friends install Norton Products
Back to Top View Gadgets's Profile Search for other posts by Gadgets Visit Gadgets's Homepage
 
cmhardwick
Senior Member
Senior Member
Avatar

Joined: July 08 2006
Location: United States
Online Status: Offline
Posts: 290
Posted: January 30 2008 at 08:37 | IP Logged Quote cmhardwick

Are you sure you have .net 2.0 loaded? Each version (1.0, 2.0 and 3.0) can be installed simultaneously and the apps that need each will use the proper one. Unlike most "version changes" for apps, these are 3 entirely different animals. You can see the .net under Add/Remove programs.

__________________
Cicero, Enjoying automation!
Back to Top View cmhardwick's Profile Search for other posts by cmhardwick Visit cmhardwick's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: January 30 2008 at 11:48 | IP Logged Quote onhiatus

Oops, I should have mentioned that .Net 2.0 is required.

Did that get it working?

Combining this app with Dave's file monitor plug in has made controlling via email quick and easy.
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
Gadgets
Senior Member
Senior Member
Avatar

Joined: January 28 2008
Location: Canada
Online Status: Offline
Posts: 178
Posted: January 30 2008 at 14:54 | IP Logged Quote Gadgets

onhiatus wrote:
Oops, I should have mentioned that .Net 2.0 is required.

Did that get it working?

Combining this app with Dave's file monitor plug in has made controlling via email quick and easy.


That would be the problem. I didn't even think about.. I had 2.0 on there before and then bought a bigger HD and re-installed everything, guess I didn't do that one. :-)

I'll do that now, and see how it goes. Thanks!!

__________________
Friends, don't let friends install Norton Products
Back to Top View Gadgets's Profile Search for other posts by Gadgets Visit Gadgets's Homepage
 
Gadgets
Senior Member
Senior Member
Avatar

Joined: January 28 2008
Location: Canada
Online Status: Offline
Posts: 178
Posted: January 30 2008 at 15:20 | IP Logged Quote Gadgets

Alright, having .NET 2.0 makes all the difference!   

Before I go any further though, I looked at your post with the contents of your outputInex.txt and your mail-###.txt files... my mail-###.txt file contents are NOTHING like yours, so before I bang my head a few more times.. I'll give you my files for you to look at.


2008-01-30_151901_outputIndex.txt

2008-01-30_151920_mail-128461975720907168.txt

__________________
Friends, don't let friends install Norton Products
Back to Top View Gadgets's Profile Search for other posts by Gadgets Visit Gadgets's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: January 31 2008 at 12:59 | IP Logged Quote onhiatus

So the outputIndex is just a list of files that need to be processed (this is the file to watch with the file monitor plugin). So it looks correct.

The mail-xxx file is not stripping out the mime information. One easy fix is to send the email as "text only" / unformatted text / whatever it's called on your client. Otherwise it should be easy enough for you to proccess the email in PH.

The way I deal with this is just use string matching - I don't try to actually parse the email. The first think my proccess macro does is convert the entire mail-xxx file to upper case ("upper()") then look for the substring for each command I expect ("HEAT ON", "HEAT OFF" "PORCH ON", "WALK OFF", etc) the beauty of this method is it does not matter that there is a lot of noise in the email (it would handle your above files just fine). The disadvantage is that there is no context, so if you sent the email "HEAT ON... PORCH ON... HEAT OFF" you might expect the heat to go on, the porch light to go on, and then the heat to go off. Instead the commands will happen in whatever order you checked for them.

After I process an email I return a status email which includes the status of all setable devices - this doubles as a "help" screen since everything is listed in the format that is expected.

So my macro does the following:
1. Reads the Index file, then deletes it.
2. Parses the index file and for each email file reads the file and deletes it.
3. Makes the file content all uppercase, and checks the received email addresses against a list of accepted emails (minimum security). If the email doesn't match then just exit.
4. Checks for any "command strings", and executes the appropriate command for any found.
5. Sends a status email back to the sender

Note that if you send a blank email, or gibberish you still get a status email back - by design.

Here's an example of my last status email:
     ----------
     Heat Off
     Fan Off
     Overhead Off
     Couch Off
     Bed1 Off
     Bed2 Off
     Charger On
     Walk Off
     ----------
     LvngRoom: 56.9
     Outside: 39.3
     Lake: 41.6

I left it pretty terse so that it could be sent back in a single sms message.

Hope this helps, Tony
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 02 2008 at 15:00 | IP Logged Quote theowl

Being the stubborn individual I am, I decided to try to get e-mail control working using the plug-in. I got it working in the following way...


  1. Plug-in checks email every 5 minutes.
  2. New messages fire EmailControl macro
  3. header/body formulas are called, loading local vars
  4. regexdiff1 breaks body up line by line
  5. Each line is evaluated via regexdiff1 for trigger phrases
  6. loop for # of lines in email
  7. loop for number of new emails
  8. end


The line by line method works and does things in the order I send. However, I'm having an issue teaching PH how to count the number of lines in the Email. I assumed I could just use a formula to count the CRLF and add 1, but there doesn't seem to be a formula to just count things in vars (that I can find). Could someone point me in the right direction?

Thanks!
Back to Top View theowl's Profile Search for other posts by theowl
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: February 02 2008 at 16:03 | IP Logged Quote TonyNo

ph_addtoglobal( id, value ) or ph_addtovar( type, id, value )
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 02 2008 at 16:41 | IP Logged Quote theowl

That would be one of the lines in the solution. What I mean is...

How would I go about counting how many ~129's there are in a string?

So far I have the following work in progress...

ph_setsystemvar("LOCAL1","0") +
ph_doloop(ph_regex("~129","{EmailBody}",[LOCAL1]+1,2,1,2) + ph_addtoglobal("EM-numlines",1),if(LOCAL2]) = 1,0,1))

Basically, it's supposed to start LOCAL1 at 0, Start Loop, Regex finds for ~129, Loop tests len of ~129 (=1 if found), Adds to EM-numlines, Do test is the if statement to reverse 1 to 0 so the loop will continue until ~129 doesn't exist (iow: Len of ~129 = 0)

Seems like a long way to go just to find out how many lines are in the email.

Only other way I can come up with is if the end of the email has a default special char that I can tests for like EOF can be tested.
Back to Top View theowl's Profile Search for other posts by theowl
 
Gadgets
Senior Member
Senior Member
Avatar

Joined: January 28 2008
Location: Canada
Online Status: Offline
Posts: 178
Posted: February 02 2008 at 16:55 | IP Logged Quote Gadgets

I think I'm going to move on to something else myself. I read the "manual" the other night, something I rarely do, I usually skim them to find what I need. However after all the difficulties I've had getting things to work, I thought maybe I was missing some steps, or a certain order to things. However, I learned next to nothing. This program is amazing and has been well thought out to be able to control most things, but when the documentation lacks so horribly I'm sure Dave is losing a lot of potential sales because of it. In reading it, there are Send Keys (which are now Formulas), Formulas in which you can use Send Keys (but aren't Send Keys formulas now?), Triggers, which can fire formulas or macros, Macros that can use forumlas to Trigger devices... then uses Send Keys.. well which is it... are there Send Keys or are there not? The problem I see is too many functions, that can be used in too many places, but not always. The manual shows the functions, but doesn't really say how to use them, or, why you would want/need to use them. For the non-programming type like myself, it is all but impossible to make sense of all these commands, how, when, and where to use them the way the docs are currently written. All of you here in the forums are a great help, and seem very patient, but do I want to have to ask for help for every little thing I want to do?.. no. I'm sure I would become a pain in the butt real quick.   
So I think I'll do sone searching for something else, and maybe check back here from time to time and see if the docs have improved. I'm sure this software will become the top of the heap, if the documentation was completely re-written, and written from an angle as if the user has next to no programming knowledge, if you could do that, everyone would then be able to make wonderful use of this very powerful program.

Thanks for all the help you offered me this past week.

Brian

__________________
Friends, don't let friends install Norton Products
Back to Top View Gadgets's Profile Search for other posts by Gadgets Visit Gadgets's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 02 2008 at 17:23 | IP Logged Quote theowl

Sorry to see you go Brian. I know there is a discussion on here about starting a wiki, hopefully Dave will like that idea.

I did find the answer to my puzzle, looking me right in the face as I knew it would be.

Set global Em-Body   [LOCAL10]--EOF--

Now, no matter what the email says, I have my EOF which regex can target very easily to find the last line.
Back to Top View theowl's Profile Search for other posts by theowl
 
Gadgets
Senior Member
Senior Member
Avatar

Joined: January 28 2008
Location: Canada
Online Status: Offline
Posts: 178
Posted: February 03 2008 at 12:27 | IP Logged Quote Gadgets

theowl wrote:
Sorry to see you go Brian. I know there is a discussion on here about starting a wiki, hopefully Dave will like that idea.

I did find the answer to my puzzle, looking me right in the face as I knew it would be.

Set global Em-Body   [LOCAL10]--EOF--

Now, no matter what the email says, I have my EOF which regex can target very easily to find the last line.


Well I'm not adverse to coming back to the product at all, but with the info in it's current form. I'll be popping in and out here anyway, just to keep tabs.

Thanks,
   Brian

__________________
Friends, don't let friends install Norton Products
Back to Top View Gadgets's Profile Search for other posts by Gadgets Visit Gadgets's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: February 04 2008 at 14:44 | IP Logged Quote onhiatus

Owl - Good job, I would definitely have gone with the plug in, except I couldn't get it to work via POP3 (seems like the interface had to be IMAP?)

Gadgets - PowerHome is pretty simple if you want it to do simple things. It gets more complex as you want it to do complex things. Dave had defined his own programming language, so you do need to program if you want it to do more than the basics. The problem with the other solutions out there is that they either lack the advanced features (in which case the basics of PowerHome can at least match them), or they were written for one persons solution (have plenty of power, but not much flexibility, or they're as - or more - complex as PH). Hopefully you can find one that is set up close enough to what you want - if not, come on back and try again!

Actually either way come back and tell us what you end up going with.

Good luck, Tony (OnHiatus)
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 05 2008 at 19:25 | IP Logged Quote theowl

Oops, I've run into a snag on the plug-in. It seems that my system was temporarily knocked off line, causing Outlook Express to drop one of those annoying "try again?" boxes. That cascaded over to PH and froze the whole works for the last 8 hours or so.

Dave: I thought the Plug-in made PH immune to this type of freeze up?

Tony: I am using POP3. However, it might be working because I already had OE set up to check the account. Previous to the plug-in, I was using PopTray to update status in PH via e-mail rules and command control. Didn't work that great, so I needed to try something else. Looks like the plug-in is just interfacing with OE to get what it needs.
Back to Top View theowl's Profile Search for other posts by theowl
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 05 2008 at 19:34 | IP Logged Quote theowl

Oops again!

PH has processed every event since 9am, all in 5 minutes without crashing...let's see M$ do that!

Anyway, the event log shows that the plug-in wasn't at fault. Last 9am event shows PH sending me an e-mail. That must have fired up OE, which tried to send it, and failed.

If I recall correctly, I should be able to fix this by switching off the internal PH sendmail system and using ph_sendsmtpemail to bypass OE.

Anyone ever figure out how to make OE shut up when it encounters network issues?
Back to Top View theowl's Profile Search for other posts by theowl
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: February 05 2008 at 21:35 | IP Logged Quote TonyNo

I'll be watching this one closely. About the only problems I have these days is due to OE.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
Gadgets
Senior Member
Senior Member
Avatar

Joined: January 28 2008
Location: Canada
Online Status: Offline
Posts: 178
Posted: February 05 2008 at 22:27 | IP Logged Quote Gadgets

onhiatus wrote:
Actually either way come back and tell us what you end up going with.

Good luck, Tony (OnHiatus)


ok, here I am to report back as requested. I spent most of Sunday surfing, installing, un-installing and surfing some more... and FINALLY late Sunday night, I found what looks to be a decent program, it's called POWERHOME!   

Yeah, there is an amazing amount of crap out there, with a lot of claims that are just not true. There is also a lot of sotware that is simply un-stable that people CHARGE for. Had I not seen PH before and played with it, I would have went probably with x10controller or HouseBOT however all I did is constantly compare it to PH. I won't use many of the features in PH I don't think, BUT being the gizmo freak I am, I like the "thought" of being able to if I please. So by late Sunday PH was back installed... and for some reason some of the formulas suddenly started making sense to me. And I have gotten it to do the following:

Run Macros
Respond to Triggers
Respond to EMAIL commands EVERYTIME (using the plugin)
Talk to me (as a reminder for a date/time)
Talk to me after an Email command has been processed
Send me email after something happens

and probably some other goofy things I tried just for the sake of trying, and got most of them to work. I'm not very smooth at it, but I hope that will come in time. I am VERY glad to see the Wiki come alive. Who knows, maybe I'll be able to contribute to it.   

Tony (OnHiatus), thanks for the encouragment.. it helped with my decision to come back to PH!

Brian


__________________
Friends, don't let friends install Norton Products
Back to Top View Gadgets's Profile Search for other posts by Gadgets Visit Gadgets's Homepage
 
Gadgets
Senior Member
Senior Member
Avatar

Joined: January 28 2008
Location: Canada
Online Status: Offline
Posts: 178
Posted: February 05 2008 at 22:29 | IP Logged Quote Gadgets

TonyNo wrote:
I'll be watching this one closely. About the only problems I have these days is due to OE.


Why don't we all use something other then OE? I HATE outlook / outlook express with a passion, and never use it. I'm only using it now because it was the only email program on my server. Maybe Thunderbird or Eudora (which I have used for years) would be a better choice??

__________________
Friends, don't let friends install Norton Products
Back to Top View Gadgets's Profile Search for other posts by Gadgets Visit Gadgets's Homepage
 

Page of 2 Next >>
  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum