|
Post by rikky on Jul 28, 2018 9:12:00 GMT 1
List all the gmail folders: INCLUDE ssl
SSL_APPEND_MARK$ = CR$ & NL$ SSL_ENDING_MARK$ = CR$ & NL$ SSL_TIMEOUT = 2000 : ' <------------------- set higher if needed
s1 = SSL_CONNECT("imap.gmail.com:993") PRINT "session handle " & STR$(s1)
'flush ssl buffer PRINT "CONNECT: ", SSL_CMD$(s1, "") PRINT "AUTH LOGIN : " & SSL_CMD$(s1, "AUTH LOGIN user@gmail.com password") PRINT "t1 LIST " & SSL_CMD$(s1,"t1 LIST " & CHR$(34) & CHR$(34) & " " & CHR$(34) & "%" & CHR$(34)) PRINT "LOGOUT : " & SSL_CMD$(s1,"t1 logout")
reference : tools.ietf.org/html/rfc6154#page-7 Rik.
|
|
|
Post by Pjot on Jul 28, 2018 13:56:58 GMT 1
Thanks Rik! The program works, and seems to be displaying results as described in the spec describing the LIST extension for IMAP. We have enough tools now to generate a mail client for all secure protocols Best regards Peter
|
|
|
Post by vovchik on Jul 29, 2018 14:29:29 GMT 1
Dear Peter and Rik, What would be nice now would be to find a rather good c-source CLI mail pro and to steal and BaConize the opt handler, to save us some experimenting and reading. With kind regards, vovchik
|
|
|
Post by rikky on Jul 29, 2018 15:17:50 GMT 1
The one I know of, and works perfectly, is called Mutt
|
|
|
Post by rikky on Jul 29, 2018 17:43:01 GMT 1
Yet another demo. INCLUDE ssl
'''''''''''''''''''''''''''''''''''' ' Fill in your account credentials ' '''''''''''''''''''''''''''''''''''' user$ = "abcdefg@gmail.com" pass$ = "hijklmn" ''''''''''''''''''''''''''''''''''''
CONST CRNL$ = CR$ & NL$ SSL_TIMEOUT = 5000 SSL_APPEND_MARK$ = CRNL$ SSL_ENDING_MARK$ = CRNL$
s1 = SSL_CONNECT("smtp.gmail.com:465")
PRINT "CONNECT: ", SSL_CMD$(s1, "") PRINT "HELO: ", SSL_CMD$(s1, "HELO basic-converter.org") PRINT "AUTH: ", SSL_CMD$(s1, "AUTH LOGIN")
PRINT "Account: ", SSL_CMD$(s1, B64ENC$(user$)) PRINT "Password: ", SSL_CMD$(s1, B64ENC$(pass$)) PRINT "Mail from: ", SSL_CMD$(s1, "mail from:<" & user$ & ">") PRINT "Rcpt to: ", SSL_CMD$(s1, "rcpt to:<" & user$ & ">")
PRINT "DATA: ", SSL_CMD$(s1, "DATA")
'It realy doesn't matter what you put here as from: or to: PRINT SSL_CMD$(s1, "From: hoeperdepoep <hoeperdepoep@gmail.com>" & CRNL$ & "To: Jan <helahola@gmail.com>" & \ CRNL$ & "Subject: test 93" & CRNL$ & \ CRNL$ & "Hello world 2 " & CRNL$ & "." & CRNL$)
' Quit the connection PRINT "QUIT: ", SSL_CMD$(s1, "QUIT")
s1 = SSL_CONNECT("imap.gmail.com:993") PRINT "session handle " & STR$(s1)
'flush ssl buffer PRINT "CONNECT: ", SSL_CMD$(s1, "") PRINT "AUTH LOGIN : " & SSL_CMD$(s1, "AUTH LOGIN " & user$ & " " & pass$)
resp$ = SSL_CMD$(s1, "command_identifier_call_this_what_you_want_nummer_1 SELECT inbox")
this_latest_mail_nr$ = "" FOR this_line$ IN resp$ STEP NL$ 'PRINT this_line$ IF INSTR(this_line$,"EXISTS") THEN PRINT this_line$ & " => nr of latest mail : " & TOKEN$(this_line$,2) this_latest_mail_nr$ = TOKEN$(this_line$,2) BREAK END IF NEXT this_line$
'read the header resp$ = SSL_CMD$(s1, "nummer_2 FETCH " & this_latest_mail_nr$ & " body[header]") PRINT resp$
'following doesn't work for some reason 'subject$ = INBETWEEN$(resp$,"Subject:" & NL$)
'find the subject subject$ = "" FOR this_line$ IN resp$ STEP NL$ 'PRINT this_line$ IF INSTR(this_line$,"Subject:") THEN subject$ = CHOP$(LAST$(this_line$,1)) BREAK END IF NEXT this_line$ PRINT "Subject : " & subject$
'Test to be sure there is not an other newer email crossposted, that you want to keep. 'Should realy use the mail_id I suppose. IF subject$ <> "test 93" THEN PRINT "oeps, this mail is about " & subject$ PRINT "keeping it." ELSE PRINT "CHECK your INBOX for test 93, then press ยต to delete it."; key = GETKEY 'mark for deletion 'STORE in \deleted , but you can store in an other folder too. resp$ = SSL_CMD$(s1, "nummer_3_ofzo STORE " & this_latest_mail_nr$ & " +FLAGS (\\Deleted)") PRINT resp$ 'PRINT "If all went well, your mail with subject 'test 93' has moved to the trash folder" 'No it doesnt, probably because my trash folder is called prullenbak.
resp$ = SSL_CMD$(s1, "en_dit_is_nummer_4 EXPUNGE") PRINT resp$ PRINT "If all went well, your mail with subject 'test 93' is now gone" END IF
SSL_CLOSE(s1)
reference : rfc3501 Rik.
|
|
|
Post by vovchik on Jul 29, 2018 19:15:00 GMT 1
Dear Rik, Thanks. It works like a charm. What is left is doing the rather complex check of arguments on the command line and creating command strings. We will then have our own little "bmail". With kind regards, vovchik
|
|
|
Post by rikky on Jul 31, 2018 20:39:55 GMT 1
Well, I have some rudimentary commandline tools prepared. All very preembrional, but you have to start somewhere. The aim is to have a minimum set of very simple tools for the email. Which is read write and delete a mail. Unfortunately, in order to achieve that, we need a few more. The whole mater is so complex that I had to make a few choises. I chose to select the mails according to there UID's, which means that you have to select the appropriate folder in which the mail resides as well, for different folders have the same UID's in them. Better is probably selecting on the real message id's, than you can avoid this hassle. That will be something for later. So the tools. SENDMAIL is meant to send a mail, yes it's true. DELETEMAIL : is deliberatly left empty, until we have a better understanding of the matter, just to avoid tears. look for an example in the post above. SEARCH : is cherry on the cake for in the future, for now it does nothing. LIST : list all your mailfolders, UID_SEARCH_ALL is the most important, it gives you all the UID's in a given folder, the newest is last. READMAIL is meant to read a mail from a given folder. The username and the password can be hardcoded in user_pass.bac which can be overridden in the command-line options. The formats: SENDMAIL file_to_send FROM username@gmail.com:password TO username@whatevermail.blop -attachment file_to_attach -subject "be sure to quote multiple words" LIST FROM username@gmail.com:password UID_SEARCH_ALL FROM username@gmail.com:password IN gmail_folder (quote if containing space) READMAIL UID uid FROM username@gmail.com:password IN gmail_folder (quote if containing space) of course, the attachment part is not implemented yet. Now there is one thing that needs attention. The IMAP commands that are send to gmail are prepended with a identifier. This is not for nothing. Sometimes you get the responses back in parts, and blablabla. So in the READMAIL I have noticed the body of the mail comes in parts, sometimes. I have tried to solve this with sending noop commands I hope I did it well Problem is, do other commands this as well? In that case all the commands need to be nooped as well. BMAIL.tgz (5.45 KB) Rik.
|
|
|
Post by vovchik on Jul 31, 2018 21:32:51 GMT 1
Dear Rik, Thanks. I will check it out tomorrow. With kind regards, vovchik
|
|
|
Post by Pjot on Aug 16, 2018 19:29:39 GMT 1
All, I was able to improve the ssl.bac context further, so it does not need the external libtomcrypt library any more.
Instead, it now uses the amalgamated 'libtomcrypt.c' in the original TLSE package. This way, we have a complete standalone solution consisting of ANSI C which should be compilable on multiple platforms. Regards Peter
|
|
|
Post by vovchik on Aug 16, 2018 21:57:44 GMT 1
Dear Peter, That sounds like a good idea. Thanks. I am getting lots of warnings and it seems to hang during the compile, but a binary that works is produced. I have attached a sample log. Don't know exactly where the problem is. To get rid of the warnings and to enble a complete compile I used "PRAGMA OPTIONS -w" at the very top, but that may not be such a great idea. With kind regards, vovchik
|
|
|
Post by Pjot on Aug 17, 2018 18:39:12 GMT 1
Hi vovchik, Indeed, as it is caused by the libcryptom library source code, the only option would be to disable compile warnings altogether. The proposed compile flag '-Woverride-init' does not seem to work. It may sound a harsh solution, but it is not that bad. A compile error still will break GCC and actually prevents a binary to be produced.
Other compilers like clang or tcc generate the same error on Mint 17.3 32bit.
Alternatively, you still can install the libtomcrypt libraries, and then replace the current PRAGMA lines for the following lines at the top of the ssl.bac wrapper: PRAGMA INCLUDE tlse-master/tlse.h PRAGMA INCLUDE tlse-master/tlse.c PRAGMA LDFLAGS -ltomcrypt PRAGMA OPTIONS -DLTM_DESC
Best regards Peter
|
|
|
Post by vovchik on Aug 17, 2018 20:42:39 GMT 1
Dear Peter, Thanks for testing. I am glad it is not only my computer that gives whose warnings. I think, for simplicity's sake, PRAGMA OPTIONS -w might be the easiest and quickest, but it is good that we have a few choices. With kind regards, vovchik
|
|
|
Post by Pjot on Aug 19, 2018 8:05:27 GMT 1
I am glad it is not only my computer that gives whose warnings. Indeed, testing on Redhat6, I can see the same warnings. So apparently, there are GCC versions which have these warnings enabled. Interestingly, on my Linux Mint 18.3 64bit which has GCC 5.4, these compile warnings do not occur. And next to this issue, I noticed a memory leak in 'tlse.c' with the root certificate memory allocation. I guess I have to contact the author and log these issue in their github tracker... Best regards Peter
|
|
|
Post by Pjot on Aug 27, 2018 18:42:38 GMT 1
I guess I have to contact the author and log these issue in their github tracker... So this is what I have done, and the author of the TLSE package kindly has fixed both issues (the memory leak and also the compile warnings). If you obtain the latest version of TLSE then the warnings should not occur anymore Best regards Peter
|
|
|
Post by rikky on Dec 14, 2018 13:34:50 GMT 1
Now it all works. user_pass, you have to adapt yourself. BMAIL_LIST_FOLDERS lists all the folders BMAIL_LIST_UIDS lists all the UID's, [IN folder] READMAIL uid prints the whole mail incl headers BMAIL_READ_DATE uid prints the DATE field BMAIL_READ_FROM uid etc BMAIL_READ_SUBJECT uid BMAIL_READ_BODY uid DELETEMAIL uid deletes the mail with uid_number uid , [IN folder] SENDMAIL file_to_send TO username@whatevermail.blop -attachment file_to_attach -subject "be sure to quote multiple words" Rik. Attachments:BMAIL.tgz (799.71 KB)
|
|