annotate plugins/chkmail.c @ 8640:818abe01efc6

[gaim-migrate @ 9392] Fix from Marina Roos committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Mon, 12 Apr 2004 13:14:02 +0000
parents a21cf07cd8e1
children a09ffb82aef1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
1 /* This is some funky code. It is still being developed by Rob Flynn - rob@linuxpimps.com
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
2 * I recommend not using this code right now. :)
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
3 */
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
4
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 #define GAIM_PLUGINS
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 #include <stdio.h>
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
8 #include <stdlib.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
9 #include <unistd.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
10 #include <string.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
11 #include <netinet/in.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
12 #include <arpa/inet.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
13 #include <sys/socket.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
14 #include <netdb.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
15 #include <netinet/in.h>
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
16 #include <pthread.h>
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 #include "gaim.h"
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
19 char username[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
20 char password[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
21 char mailhost[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
22 int mailport = 110;
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
23 int state = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
24
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25 static void *handle = NULL;
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
26 extern GtkWidget *buddies;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
27
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
28 int lastnum = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
29 int orig = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
30 int mytimer;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
31
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
32 void update_mail();
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
33 void check_mail();
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
34
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
35 int num_msgs()
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
36 {
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
37 struct in_addr *sin;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
38 char recv[1024];
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
39 char command[256];
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
40 int fd;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
41 int num = 0;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
42 int step = 0;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
43 int len;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
44
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
45 sin = (struct in_addr *)get_address(mailhost);
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
46 fd = connect_address(sin->s_addr, mailport);
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
47 while ((len = read(fd, recv, 1023))>0) {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
48 recv[len] = 0;
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
49 if (!strncmp(recv, "-ERR", strlen("-ERR"))) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
50 step = 4;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
51 break;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
52 } else if (!strncmp(recv, "+OK", strlen("+OK"))) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
53 if (step == 3) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
54 if (sscanf(recv, "+OK %d %d\n", &num, &step) != 2)
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
55 break;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
56 g_snprintf(command, sizeof(command), "QUIT\n");
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
57 write(fd, command, strlen(command));
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
58 close(fd);
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
59 return num;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
60 }
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
61
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
62 if (step == 0) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
63 g_snprintf(command, sizeof(command), "USER %s\n", username);
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
64 write(fd, command, strlen(command));
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
65 step = 1;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
66 } else if (step == 1) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
67 g_snprintf(command, sizeof(command), "PASS %s\n", password);
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
68 write(fd, command, strlen(command));
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
69 step = 2;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
70 } else if (step == 2) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
71 g_snprintf(command, sizeof(command), "STAT\n");
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
72 write(fd, command, strlen(command));
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
73 step = 3;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
74 }
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
75 }
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
76 }
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
77 close(fd);
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
78
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
79 return 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
80 }
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
81
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
82 void destroy_mail_list()
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
83 {
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
84 GList *list;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
85 GtkWidget *w;
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
86
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
87 list = GTK_TREE(buddies)->children;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
88 while (list) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
89 w = (GtkWidget *)list->data;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
90 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, _("Mail Server"))) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
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
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
93 if (!list)
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
94 break;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
95 }
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
96 list = list->next;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
97 }
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
98 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
99
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
100
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
101 void setup_mail_list()
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
102 {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
103 GList *list;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
104 GtkWidget *w;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
105 GtkWidget *item;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
106 GtkWidget *tree;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
107 gchar *buf;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
108
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
109 list = GTK_TREE(buddies)->children;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
110
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
111 while (list) {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
112 w = (GtkWidget *)list->data;
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
113 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, _("Mail Server"))) {
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
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
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
116 if (!list)
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
117 break;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
118 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
119 list = list->next;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
120 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
121
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
122 item = gtk_tree_item_new_with_label(_("Mail Server"));
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
123 tree = gtk_tree_new();
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
124 gtk_widget_show(item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
125 gtk_widget_show(tree);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
126 gtk_tree_append(GTK_TREE(buddies), item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
127 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
128 gtk_tree_item_expand(GTK_TREE_ITEM(item));
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
129
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
130 buf = g_malloc(BUF_LONG);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
131
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
132 g_snprintf(buf, BUF_LONG, _("%s (%d new/%d total)"), mailhost, lastnum - orig, lastnum);
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
133 item = gtk_tree_item_new_with_label(buf);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
134 g_free(buf);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
135
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
136 gtk_tree_append(GTK_TREE(tree), item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
137 gtk_widget_show(item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
138 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
139
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140 void gaim_plugin_init(void *h) {
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
141 handle = h;
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
142
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
143 orig = num_msgs();
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
144 lastnum = orig;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
145
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
146 gaim_signal_connect(handle, event_blist_update, setup_mail_list, NULL);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
147 setup_mail_list();
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
148
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 127
diff changeset
149 mytimer = g_timeout_add(30000, check_mail, NULL);
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
150 }
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
151
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
152 void check_mail() {
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
153 pthread_t mail_thread;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
154 pthread_attr_t attr;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
155
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
156 if (state == 0) {
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
157 state = 1;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
158 pthread_attr_init(&attr);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
159 pthread_create(&mail_thread, &attr, (void *)&update_mail, NULL);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
160 }
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
163 void update_mail () {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
164 int newnum;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
165
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 127
diff changeset
166 g_source_remove(mytimer);
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
167
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
168 newnum = num_msgs();
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
169
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
170 if ((newnum >= lastnum) && (newnum > 0)) {
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
171 newnum = newnum - lastnum;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
172 } else {
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
173 newnum = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
174 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
175
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
176 if (newnum < lastnum) {
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
177 orig = lastnum;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
178 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
179
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
180 lastnum = newnum;
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 127
diff changeset
181 mytimer = g_timeout_add(30000, check_mail, NULL);
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
182 setup_mail_list();
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
183 state = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
184 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
185
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
186
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
187 void gaim_plugin_remove() {
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 127
diff changeset
188 g_source_remove(mytimer);
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
189 while (state == 1) { }
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
190 destroy_mail_list();
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
191 handle = NULL;
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
192 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
193
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
194 char *name() {
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
195 return _("Check Mail");
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
196 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
197
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
198 char *description() {
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
199 return _("Check email every X seconds.\n");
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200 }