13 #include <X11/Xutil.h>
14 #include <X11/Xatom.h>
15 #include <X11/Xft/Xft.h>
17 #include "string_utils.h"
18 #include "file_utils.h"
21 #include "md5_utils.h"
23 #include "icons_utils.h"
25 static struct mail_entry mail
;
27 void parse_file(const char *filename
)
35 fh
= fopen(filename
, "r");
39 fprintf(stderr
, "-------------------------------------------\n");
40 fprintf(stderr
, "Test file: %s\n", filename
);
41 fprintf(stderr
, "-------------------------------------------\n");
44 while (fgets(buf
, sizeof(buf
), fh
)) {
45 if (!strncmp(buf
, "From:", 5)) {
46 rfc5322_extract_address(mail
.addr
, buf
, sizeof(mail
.addr
));
47 crlf
= strrchr(buf
, '\n');
51 md5_calc_sum(mail
.addr
, mail
.addr_md5
);
53 } else if (!strncmp(buf
, "Subject:", 8)) {
54 rfc5322_extract_subject(mail
.subj
, buf
, sizeof(mail
.subj
));
57 printf("[SKIP] ------- %s", buf
);
65 static void print_mail(struct mail_entry
*mail
)
72 fprintf(stderr
, "-------------------------------------------\n");
73 fprintf(stderr
, "\"%s\" [", mail
->addr
);
74 for (i
= 0; i
< 16; i
++) {
75 fprintf(stderr
, "%02x", mail
->addr_md5
[i
]);
77 fprintf(stderr
, "] %s\n", mail
->subj
);
80 void display_osd(int argc
, char **argv
)
82 struct notify_object no
;
91 /* Open connection with the server */
92 dpy
= XOpenDisplay(NULL
);
94 fprintf(stderr
, "Cannot open display\n");
98 icon
= icon_get_path((char *) mail
.addr_md5
);
100 osd_init(dpy
, &no
, mail
.addr
, mail
.subj
, icon
);
102 if (osd_new_frame(argc
, argv
, &no
)) {
107 /* Select kind of events we are interested in */
108 XSelectInput(no
.frame
.display
, no
.frame
.win
,
109 ExposureMask
| KeyPressMask
| ButtonPressMask
);
111 /* Create OSD object */
112 if (osd_new_notify_object(argc
, argv
, &no
)) {
116 /* Map (show) the window */
117 XMapWindow(no
.frame
.display
, no
.frame
.win
);
121 XNextEvent(no
.frame
.display
, &e
);
125 /* Draw or redraw the window */
126 osd_show_notify_object(&no
);
129 /* Exit on key press or mouse button press */
137 osd_delete_notify_object(&no
);
140 icon_free_path(icon
);
142 /* Close connection to server */
143 XCloseDisplay(no
.frame
.display
);
146 int main(int argc
, char **argv
)
151 fprintf(stderr
, "%s <file>\n", argv
[0]);
164 display_osd(argc
, argv
);