Mercurial > pidgin.yaz
comparison plugins/chkmail.c @ 114:668727c82810
[gaim-migrate @ 124]
Wagii
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Fri, 14 Apr 2000 08:19:10 +0000 |
parents | c76d4c0c5e3a |
children | 5f294f7c4f2e |
comparison
equal
deleted
inserted
replaced
113:52bfcdc72dcc | 114:668727c82810 |
---|---|
1 /* This is some funky code. It is still being developed by Rob Flynn - rob@linuxpimps.com | |
2 * I recommend not using this code right now. :) | |
3 */ | |
4 | |
1 #define GAIM_PLUGINS | 5 #define GAIM_PLUGINS |
2 | 6 |
3 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | |
9 #include <unistd.h> | |
10 #include <string.h> | |
11 #include <netinet/in.h> | |
12 #include <arpa/inet.h> | |
13 #include <sys/socket.h> | |
14 #include <netdb.h> | |
15 #include <netinet/in.h> | |
4 #include "gaim.h" | 16 #include "gaim.h" |
17 | |
18 char username[] = ""; | |
19 char password[] = ""; | |
20 char mailhost[] = ""; | |
21 int mailport = 110; | |
5 | 22 |
6 static void *handle = NULL; | 23 static void *handle = NULL; |
7 extern GtkWidget *blist; | 24 extern GtkWidget *blist; |
8 GtkWidget *maily; | 25 GtkWidget *maily; |
9 GtkWidget *vbox2; | 26 GtkWidget *vbox2; |
27 GtkWidget *yo; | |
28 | |
10 GList *tmp; | 29 GList *tmp; |
30 int lastnum = 0; | |
31 int orig = 0; | |
32 int mytimer; | |
33 | |
34 void update_mail(); | |
35 | |
36 int num_msgs() | |
37 { | |
38 struct in_addr *sin; | |
39 char recv[1024]; | |
40 char command[256]; | |
41 int fd; | |
42 int num = 0; | |
43 int step = 0; | |
44 int len; | |
45 | |
46 sin = (struct in_addr *)get_address(mailhost); | |
47 fd = connect_address(sin->s_addr, mailport); | |
48 while ((len = read(fd, recv, 1023))>0) { | |
49 recv[len] = 0; | |
50 if (!strncmp(recv, "-ERR", strlen("-ERR"))) { step = 4; break; | |
51 } else if (!strncmp(recv, "+OK", strlen("+OK"))) { | |
52 if (step == 3) { | |
53 if (sscanf(recv, "+OK %d %d\n", &num, &step) != 2) | |
54 break; | |
55 g_snprintf(command, sizeof(command), "QUIT\n"); | |
56 write(fd, command, strlen(command)); | |
57 close(fd); | |
58 return num; | |
59 } | |
60 | |
61 if (step == 0) { | |
62 g_snprintf(command, sizeof(command), "USER %s\n", username); | |
63 write(fd, command, strlen(command)); | |
64 step = 1; | |
65 } else if (step == 1) { | |
66 g_snprintf(command, sizeof(command), "PASS %s\n", password); | |
67 write(fd, command, strlen(command)); | |
68 step = 2; | |
69 } else if (step == 2) { | |
70 g_snprintf(command, sizeof(command), "STAT\n"); | |
71 write(fd, command, strlen(command)); | |
72 step = 3; | |
73 } | |
74 } | |
75 } | |
76 close(fd); | |
77 return 0; | |
78 } | |
11 | 79 |
12 void gaim_plugin_init(void *h) { | 80 void gaim_plugin_init(void *h) { |
13 handle = h; | 81 handle = h; |
14 printf("Wahoo\n"); | |
15 tmp = gtk_container_children(GTK_CONTAINER(blist)); | 82 tmp = gtk_container_children(GTK_CONTAINER(blist)); |
16 | 83 |
17 maily = gtk_label_new("TESTING!!!"); | 84 maily = gtk_label_new("You have no new email"); |
18 vbox2 = (GtkWidget *)tmp->data; | 85 vbox2 = (GtkWidget *)tmp->data; |
19 | 86 |
20 gtk_box_pack_start(GTK_BOX(vbox2), maily, FALSE, FALSE, 5); | 87 yo = gtk_frame_new(NULL); |
21 gtk_box_reorder_child(GTK_BOX(vbox2), maily, 2); | 88 gtk_frame_set_shadow_type(GTK_FRAME(yo), GTK_SHADOW_IN ); |
89 gtk_widget_show(yo); | |
90 | |
91 gtk_box_pack_start(GTK_BOX(vbox2), yo, FALSE, FALSE, 5); | |
92 gtk_box_reorder_child(GTK_BOX(vbox2), yo, 2); | |
93 gtk_container_add(GTK_CONTAINER(yo), maily); | |
94 | |
22 gtk_widget_show(maily); | 95 gtk_widget_show(maily); |
96 | |
97 orig = num_msgs(); | |
98 lastnum = orig; | |
99 | |
100 mytimer = gtk_timeout_add(30000, (GtkFunction)update_mail, NULL); | |
23 } | 101 } |
102 | |
103 void update_mail () { | |
104 int newnum; | |
105 gchar *buf; | |
106 | |
107 gtk_timeout_remove(mytimer); | |
108 | |
109 newnum = num_msgs(); | |
110 | |
111 buf = g_malloc(BUF_LONG); | |
112 | |
113 if ( (newnum >= lastnum) && (newnum > 0)) { | |
114 g_snprintf(buf, BUF_LONG, "You have %d new e-mail(s)", newnum - orig); | |
115 } else { | |
116 g_snprintf(buf, BUF_LONG, "You have no new email"); | |
117 } | |
118 | |
119 gtk_widget_destroy(maily); | |
120 maily = gtk_label_new(buf); | |
121 g_free(buf); | |
122 | |
123 gtk_container_add(GTK_CONTAINER(yo), maily); | |
124 | |
125 gtk_widget_show(maily); | |
126 | |
127 if (newnum < lastnum) { | |
128 orig = 0; | |
129 } | |
130 | |
131 lastnum = newnum; | |
132 mytimer = gtk_timeout_add(30000, (GtkFunction)update_mail, NULL); | |
133 } | |
134 | |
24 | 135 |
25 void gaim_plugin_remove() { | 136 void gaim_plugin_remove() { |
26 handle = NULL; | 137 handle = NULL; |
27 gtk_widget_hide(maily); | 138 gtk_widget_hide(maily); |
28 gtk_widget_destroy(maily); | 139 gtk_widget_destroy(yo); |
140 gtk_timeout_remove(mytimer); | |
29 } | 141 } |
30 | 142 |
31 char *name() { | 143 char *name() { |
32 return "Check Mail"; | 144 return "Check Mail"; |
33 } | 145 } |