Mercurial > pidgin.yaz
annotate plugins/chkmail.c @ 9465:8a4797a608ae
[gaim-migrate @ 10290]
1) Fixes the parsing for Win32 clipboard format so that we more accurately
grab the right text
2) Revises our Win32 clipboard format conversion to act more like IE,
since this is as close as we will get to "the right way"
3) Makes clipboard pasting not paste HTML comments (this one effects
linux too, and fixes a problem i've seen pasting from oo.o)
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Wed, 07 Jul 2004 01:35:27 +0000 |
parents | a21cf07cd8e1 |
children | a09ffb82aef1 |
rev | line source |
---|---|
114 | 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 | |
105 | 5 #define GAIM_PLUGINS |
6 | |
7 #include <stdio.h> | |
114 | 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> | |
127 | 16 #include <pthread.h> |
105 | 17 #include "gaim.h" |
18 | |
114 | 19 char username[] = ""; |
20 char password[] = ""; | |
21 char mailhost[] = ""; | |
22 int mailport = 110; | |
127 | 23 int state = 0; |
114 | 24 |
105 | 25 static void *handle = NULL; |
124 | 26 extern GtkWidget *buddies; |
114 | 27 |
28 int lastnum = 0; | |
29 int orig = 0; | |
30 int mytimer; | |
31 | |
32 void update_mail(); | |
127 | 33 void check_mail(); |
114 | 34 |
35 int num_msgs() | |
36 { | |
6308 | 37 struct in_addr *sin; |
38 char recv[1024]; | |
39 char command[256]; | |
40 int fd; | |
41 int num = 0; | |
42 int step = 0; | |
43 int len; | |
114 | 44 |
6308 | 45 sin = (struct in_addr *)get_address(mailhost); |
46 fd = connect_address(sin->s_addr, mailport); | |
114 | 47 while ((len = read(fd, recv, 1023))>0) { |
48 recv[len] = 0; | |
6308 | 49 if (!strncmp(recv, "-ERR", strlen("-ERR"))) { |
50 step = 4; | |
51 break; | |
52 } else if (!strncmp(recv, "+OK", strlen("+OK"))) { | |
53 if (step == 3) { | |
54 if (sscanf(recv, "+OK %d %d\n", &num, &step) != 2) | |
55 break; | |
56 g_snprintf(command, sizeof(command), "QUIT\n"); | |
57 write(fd, command, strlen(command)); | |
114 | 58 close(fd); |
6308 | 59 return num; |
60 } | |
114 | 61 |
6308 | 62 if (step == 0) { |
63 g_snprintf(command, sizeof(command), "USER %s\n", username); | |
64 write(fd, command, strlen(command)); | |
65 step = 1; | |
66 } else if (step == 1) { | |
67 g_snprintf(command, sizeof(command), "PASS %s\n", password); | |
68 write(fd, command, strlen(command)); | |
69 step = 2; | |
70 } else if (step == 2) { | |
71 g_snprintf(command, sizeof(command), "STAT\n"); | |
72 write(fd, command, strlen(command)); | |
73 step = 3; | |
74 } | |
75 } | |
76 } | |
77 close(fd); | |
78 | |
114 | 79 return 0; |
80 } | |
105 | 81 |
124 | 82 void destroy_mail_list() |
83 { | |
6308 | 84 GList *list; |
85 GtkWidget *w; | |
124 | 86 |
6308 | 87 list = GTK_TREE(buddies)->children; |
88 while (list) { | |
89 w = (GtkWidget *)list->data; | |
90 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, _("Mail Server"))) { | |
91 gtk_tree_remove_items(GTK_TREE(buddies), list); | |
126
b4cd83f1d0b8
[gaim-migrate @ 136]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
124
diff
changeset
|
92 list = GTK_TREE(buddies)->children; |
6308 | 93 if (!list) |
94 break; | |
95 } | |
96 list = list->next; | |
97 } | |
124 | 98 } |
99 | |
100 | |
101 void setup_mail_list() | |
102 { | |
103 GList *list; | |
104 GtkWidget *w; | |
105 GtkWidget *item; | |
106 GtkWidget *tree; | |
107 gchar *buf; | |
108 | |
109 list = GTK_TREE(buddies)->children; | |
110 | |
111 while (list) { | |
112 w = (GtkWidget *)list->data; | |
5116 | 113 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, _("Mail Server"))) { |
124 | 114 gtk_tree_remove_items(GTK_TREE(buddies), list); |
126
b4cd83f1d0b8
[gaim-migrate @ 136]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
124
diff
changeset
|
115 list = GTK_TREE(buddies)->children; |
124 | 116 if (!list) |
117 break; | |
118 } | |
119 list = list->next; | |
120 } | |
121 | |
5116 | 122 item = gtk_tree_item_new_with_label(_("Mail Server")); |
124 | 123 tree = gtk_tree_new(); |
124 gtk_widget_show(item); | |
125 gtk_widget_show(tree); | |
126 gtk_tree_append(GTK_TREE(buddies), item); | |
127 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree); | |
128 gtk_tree_item_expand(GTK_TREE_ITEM(item)); | |
129 | |
130 buf = g_malloc(BUF_LONG); | |
131 | |
5116 | 132 g_snprintf(buf, BUF_LONG, _("%s (%d new/%d total)"), mailhost, lastnum - orig, lastnum); |
124 | 133 item = gtk_tree_item_new_with_label(buf); |
134 g_free(buf); | |
135 | |
136 gtk_tree_append(GTK_TREE(tree), item); | |
137 gtk_widget_show(item); | |
138 } | |
139 | |
105 | 140 void gaim_plugin_init(void *h) { |
141 handle = h; | |
142 | |
114 | 143 orig = num_msgs(); |
144 lastnum = orig; | |
145 | |
124 | 146 gaim_signal_connect(handle, event_blist_update, setup_mail_list, NULL); |
147 setup_mail_list(); | |
148 | |
4168 | 149 mytimer = g_timeout_add(30000, check_mail, NULL); |
127 | 150 } |
151 | |
152 void check_mail() { | |
153 pthread_t mail_thread; | |
154 pthread_attr_t attr; | |
155 | |
156 if (state == 0) { | |
157 state = 1; | |
158 pthread_attr_init(&attr); | |
159 pthread_create(&mail_thread, &attr, (void *)&update_mail, NULL); | |
160 } | |
105 | 161 } |
162 | |
114 | 163 void update_mail () { |
164 int newnum; | |
165 | |
4168 | 166 g_source_remove(mytimer); |
114 | 167 |
168 newnum = num_msgs(); | |
169 | |
6308 | 170 if ((newnum >= lastnum) && (newnum > 0)) { |
127 | 171 newnum = newnum - lastnum; |
114 | 172 } else { |
124 | 173 newnum = 0; |
114 | 174 } |
175 | |
176 if (newnum < lastnum) { | |
127 | 177 orig = lastnum; |
114 | 178 } |
179 | |
180 lastnum = newnum; | |
4168 | 181 mytimer = g_timeout_add(30000, check_mail, NULL); |
124 | 182 setup_mail_list(); |
127 | 183 state = 0; |
114 | 184 } |
185 | |
186 | |
105 | 187 void gaim_plugin_remove() { |
4168 | 188 g_source_remove(mytimer); |
127 | 189 while (state == 1) { } |
124 | 190 destroy_mail_list(); |
105 | 191 handle = NULL; |
192 } | |
193 | |
194 char *name() { | |
5116 | 195 return _("Check Mail"); |
105 | 196 } |
197 | |
198 char *description() { | |
5116 | 199 return _("Check email every X seconds.\n"); |
105 | 200 } |