2lss
Full Member
Posts: 140
|
Post by 2lss on Dec 17, 2010 8:42:09 GMT 1
I use a little program in Ubuntu called mail-notification, which displays an indicator in the tray when you get new mail.
There are some things I don't like about it though. So I decided to create my own using bacon.
When you start the program, an icon appears in the tray. Clicking on it brings up a window where you can input your username, password, and set the update interval. Don't worry, none of the information is stored in a file (until I figure out how to encrypt it).
When you get a new message, the icon will blink until you click on it and the tooltip will display the six latest messages.
The only drawback is that it needs curl to download the xml for the account because I have no clue how to implement it in bacon code.
Here is my todo list:
* Find a good place to put the icon OR figure out how to compile into program * Fix window repositioning after hide/unhide * Add support for .config file w/ password encryption * Clean up code * Create nicer tooltip using GtkTooltip * Use GtkTable to position widgets instead of GtkFixed * Create a function to replace curl * Possible add support for other mail servers
Any suggestions let me know! ;D
|
|
|
Post by Pjot on Dec 17, 2010 22:09:40 GMT 1
Very cool!! I see you use 'curl' to setup a HTTPS connection. Good idea! Probably a similar thing can be done by importing some HTTPS functions from 'libCurl', or, if you are in a daring mood, import SSL functions from 'libcrypto' and 'libssl'. If I have time I will look at it, too. For encryption of username and password, you can use an 'openssl' command, just like I do in my PassWord Manager Program in the function 'Save_Data', to store data in a file. Thanks for this nice contribution! Peter
|
|
|
Post by Pjot on Dec 18, 2010 0:09:12 GMT 1
Well I got something running with imported functions from 'libCurl', so you can use this instead of the Curl binary, if you like. Still you need 'libCurl', of course ' --------------------------------------------------------------------------------------
TRAP LOCAL CATCH GOTO handle_error
lib$ = "libcurl.so" seq = -1
LABEL import_retry INCR seq retry = FALSE IMPORT "curl_easy_init" FROM lib$ TYPE long IF retry THEN GOTO import_retry
GOTO contin
LABEL handle_error ERROR = 0 IF seq IS 0 THEN lib$ = "libcurl.so.0" ELSE lib$ = CONCAT$(LEFT$(lib$, INSTRREV(lib$, ".")), STR$(seq)) IF seq < 50 THEN retry = TRUE ELSE PRINT "Curl library not found!" END END IF RESUME
LABEL contin
CATCH RESET
CONST CURLOPT_FILE = 10001 CONST CURLOPT_WRITEDATA = 10001 CONST CURLOPT_URL = 10002 CONST CURLOPT_USERPWD = 10005 CONST CURLOPT_WRITEFUNCTION = 20011
IMPORT "curl_easy_setopt(long,int,...)" FROM lib$ TYPE int IMPORT "curl_easy_perform(long)" FROM lib$ TYPE int IMPORT "curl_easy_cleanup(long)" FROM lib$ TYPE void
' --------------------------------------------------------------------------------------
' We store our data in this variable DECLARE mail$
' Callback to let Curl gather data FUNCTION Save_Data(void *buffer$, size_t size, size_t nmemb, void *userp)
mail$ = CONCAT$(mail$, (char*)buffer$) RETURN size*nmemb
END FUNCTION
' Create the handle easyhandle = curl_easy_init()
' Set the options curl_easy_setopt(easyhandle, CURLOPT_URL, "https://mail.google.com/mail/feed/atom") curl_easy_setopt(easyhandle, CURLOPT_USERPWD, "name:passwd") curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, Save_Data)
' Perform the GET success = curl_easy_perform(easyhandle)
' Cleanup curl_easy_cleanup(easyhandle)
PRINT mail$
|
|
2lss
Full Member
Posts: 140
|
Post by 2lss on Dec 18, 2010 5:41:09 GMT 1
Wow! Thats awesome, many thanks Peter. I will be including it in the next version, along with the encrypted config file. I also noticed on the curl website that it supports imap, so in the future I could add support other mail servers. Sadly though, I'm going to have to rename the project b/c "Gmail Notify" is already taken. (by a python script )
|
|
2lss
Full Member
Posts: 140
|
Post by 2lss on Dec 18, 2010 5:53:45 GMT 1
I'm uploading a bugfix version which fixes an issue with the tooltip when you have 12+ emails.
|
|
|
Post by Pjot on Dec 18, 2010 21:39:35 GMT 1
Hi 2lss, Great, thanks again! Furthermore I have created a full CURL context which can be included to your program, if you want. Some demonstration programs can be found on the BaCon website. Regards Peter PS I have to make a rectification here, the CURL library already was ported to BaCon by Doyle Whisenant, but this version never was posted to the BaCon website. Credits have been adapted.
|
|
|
Post by Pjot on Jul 20, 2019 21:30:21 GMT 1
All, Well, this is an old thread. But a valid one nevertheless. I also like to see an indicator in my systray as an indication for new mail. So I thought to refurbish this idea completely using IMAP over SSL. The below program works my with ISP in Amsterdam, but it also works with GMail. Please set your credentials at the top. Note that GMail allows a refresh rate of minimal 15 minutes (or higher). The code requires the presence of GTK2 and OpenSSL development files on your system. It is simple and can be expanded for sure. But for my current needs it is sufficient BR Peter ' Do not choke on GTK functions OPTION PARSE FALSE
' Enable TLS OPTION TLS TRUE
' Using GTK2 PRAGMA INCLUDE <gtk/gtk.h> PRAGMA OPTIONS `pkg-config --cflags gtk+-2.0` PRAGMA LDFLAGS `pkg-config --libs gtk+-2.0`
CONST CRNL$ = CR$ & NL$
CONST Mail_Server$ = "imap.gmail.com" CONST User_Name$ = "account@gmail.com" CONST Pass_Word$ = "password"
DECLARE Mail_Icon TYPE GtkStatusIcon*
'---------------------------------------------------------------------------
FUNCTION Clear_Icon(GtkStatusIcon *status_icon, GdkEvent *event, gpointer user_data)
gtk_status_icon_set_visible(Mail_Icon, FALSE) RETURN TRUE
ENDFUNCTION
'---------------------------------------------------------------------------
FUNCTION Interaction$(connection, command$)
LOCAL data$, response$
SEND command$ & CRNL$ TO connection
WHILE WAIT(connection, 2000) RECEIVE data$ FROM connection response$ = response$ & data$ IF REGEX(response$, CRNL$ & "$") THEN BREAK WEND
RETURN response$
ENDFUNCTION
'---------------------------------------------------------------------------
SUB Check_Mail
LOCAL new_mail, net LOCAL info$, result$, item$
OPEN Mail_Server$ & ":993" FOR NETWORK AS net RECEIVE info$ FROM net
result$ = Interaction$(net, "AUTH LOGIN " & User_Name$ & " " & CHR$(34) & Pass_Word$ & CHR$(34))
IF NOT(TALLY(result$, "AUTH OK")) THEN gtk_status_icon_set_from_stock(Mail_Icon, "gtk-no") gtk_status_icon_set_tooltip(Mail_Icon, "ERROR: Could not login mailserver.") gtk_status_icon_set_visible(Mail_Icon, TRUE) ELSE result$ = Interaction$(net, "session SELECT INBOX") result$ = Interaction$(net, "session SEARCH UNSEEN")
IF AMOUNT(HEAD$(result$, 1, CRNL$)) > 2 THEN gtk_status_icon_set_from_stock(Mail_Icon, "gtk-yes") gtk_status_icon_set_visible(Mail_Icon, TRUE) gtk_status_icon_set_tooltip(Mail_Icon, "There is new mail for you!") ELSE gtk_status_icon_set_visible(Mail_Icon, FALSE) ENDIF
result$ = Interaction$(net, "session LOGOUT") ENDIF
CLOSE NETWORK net
' Interval to check mail, Gmail supports 15 minutes or longer ALARM Check_Mail, 15*60*1000
ENDSUB
'---------------------------------------------------------------------------
' Init GTK gtk_init(0, 0)
' Define icon Mail_Icon = gtk_status_icon_new_from_stock("gtk-yes") gtk_status_icon_set_visible(Mail_Icon, FALSE) g_signal_connect_data(Mail_Icon, "button-press-event", G_CALLBACK(Clear_Icon), 0, 0, 0)
' Start checking mail Check_Mail()
' Endless loop gtk_main()
EDIT: clicking the icon with your mouse will make it disappear.
|
|