POP IMAP information

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
cyb3rg3cko
Posts: 7
Joined: Sun Oct 27, 2013 6:24 am

POP IMAP information

Post by cyb3rg3cko » Tue Jul 07, 2015 9:31 pm

I'm trying to communicate with gmail through the use the POP3 protocol. I've searched the web and the forums and found very little information floating around when it comes to using a secure socket with livecode. currently I'm only trying to verify communication with the "+OK ..." response from the server. I setup my address with the following code;

Code: Select all

put "gmail_pop_address" into serverAddress
put any line of hostnameToAddress(serverAddress) into socketAddress
put ":995" after socketAddress
This sets me up with an ip address and port wich i've verified is correct. Then I have tried opening a secure socket with the following methods;

Attempt 1:

Code: Select all

open socket to socketAddress with message "socketOpen"

on socketOpen
  secure socket socketAddress 
  read from socket socketAddress until CRLF
  answer "Data: " & it
 end socketOpen
Attempt 2:

Code: Select all

open secure socket to socketAddress with message "socketOpen"

on socketOpen
  read from socket socketAddress until CRLF
  answer "Data: " & it
 end socketOpen
Both attempts result in a connection being made as well as a dialog box that just contains "Data:" and no response, which you would think meant that it received at the bare minimum a CRLF ending, but even if i try to check the length of the response it comes up to 0. Please note that the code above is not a direct copy and paste from my project but an adaptation of what methods I've used. I also have a provision for a connection timeout which works when i try to connect to a non-SSL port like 110. Both POP3 or IMAP will work for my project, so information on either is welcome. I've also tried (unsuccessfully) working with Sarah Reichelt's POP library with a few modifications for SSL. I have also verified the working of the server side POP3 connection using a web based tester. I would prefer to build a small library for my particular application versus using a pre-built one, I rather enjoy learning new protocols.

Information you may want...
Livecode version - 7.0.6
Development OS - Windows/Linux(Ubuntu 15.04)
Application target OS - Both windows and Linux but primarily Linux

Thank you for any input.
Last edited by cyb3rg3cko on Wed Jul 08, 2015 11:02 am, edited 1 time in total.

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Re: POP IMAP information

Post by SparkOut » Tue Jul 07, 2015 9:57 pm

Try adding the word "with" to attempt 2's first line.
It looks like it should work then.

cyb3rg3cko
Posts: 7
Joined: Sun Oct 27, 2013 6:24 am

Re: POP IMAP information

Post by cyb3rg3cko » Wed Jul 08, 2015 11:02 am

Spark out - Thanks for the reply, as I mentioned in my original post those code snippets were adaptations of what I actually had in the program and not directy cut and pasted. I checked just to verify but in the original code I did have the 'with' keyword, I will however edit my original post to reflect that.

So 40 views and no other input? I take it this isn't a common use is the world of programming livecode.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: POP IMAP information

Post by Simon » Wed Jul 08, 2015 7:17 pm

Using sockets seems more of a pain then just using the gmail api.

Simon
Edit; I take it back, gmail api requires OAuth2. Now that is a different thread.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

cyb3rg3cko
Posts: 7
Joined: Sun Oct 27, 2013 6:24 am

Re: POP IMAP information

Post by cyb3rg3cko » Thu Jul 09, 2015 12:57 am

For anyone looking for information on this, I was able to open a secure connection to gmail's pop address using the following code;

Code: Select all

on socketConnect
  put "gmail_pop_address" into serverAddress
  put any line of hostnameToAddress(serverAddress) into socketAddress
  put ":995" after socketAddress
  open secure socket to socketAddress with message "socketOpen" without verification
end socketConnect

on socketOpen
  read from socket socketAddress until CRLF
  answer "Data: " & it
end socketOpen
Substitute "gmail_pop_address" for gmail's actual pop address (had to use this because the Livecode forums thought i was trying to use a web link). The important change is that I had to specify "without verification" because apparently when not declared it defaults to "with verification".

Note to LiveCode developers: The 'open secure socket' function should really be documented a bit better, I have seen many unanswered questions on the web in my attempt to find a solution and the documentation implies that the socket should already be open before attempting to secure it. However on a more positive note, I am fairly proficient in 5+ programming languages but still prefer to always try LiveCode first when building an application because of it being simple yet powerful with the ability compile for multiple platforms, Thank you for all your hard work bringing such a versatile tool to the world!

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Re: POP IMAP information

Post by SparkOut » Thu Jul 09, 2015 7:46 am

For reasons of my own, I had been playing with Sarah's library and gmail just a few days before your question. I didn't get the library to work, but didn't spend a lot of time on it. I did get success with your "attempt 2" code.
Are you now OK with the whole thing, or are there any "next steps" within the socket communication that are still troublesome?

cyb3rg3cko
Posts: 7
Joined: Sun Oct 27, 2013 6:24 am

Re: POP IMAP information

Post by cyb3rg3cko » Thu Jul 09, 2015 10:58 am

Once I managed to get it to connect securely to Gmail I was able to login, retrieve mail and logout with both the imap and pop3 protocols. At this point I believe I am good to go with my application. I may however write a small email library available to anyone that will make sending and receiving with pop3, imap, and smtp protocols a breeze. On one side note I did change the attempt code to use

Code: Select all

read from socket socketAddress until 0 
This enabled me to read the entire responce versus just the first line.

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Re: POP IMAP information

Post by SparkOut » Thu Jul 09, 2015 11:01 pm

OK great, good luck and if you get to making a public library for secure email collection I would be keen to look it over.

golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

Re: POP IMAP information

Post by golife » Thu Mar 24, 2016 11:22 am

I am also trying working out access to Gmail through POP3, IMAP and Gmail API (OAuth 2). Do you have such library already? Or could you post eventually the "log in" procedure script from start to end?

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: POP IMAP information

Post by quailcreek » Thu Mar 24, 2016 5:58 pm

I think a lot of us would be interested in hearing more. Would your process work on iOS?
Tom
MacBook Pro OS Mojave 10.14

Post Reply