Mercurial > pidgin
annotate plugins/mailchk.c @ 3752:b32474e522fa
[gaim-migrate @ 3890]
From: "William T. Mahan" <wtm2@duke.edu>
This patch, against CVS HEAD, fixes three bugs in Oscar File Transfer
support. I can split it up further if desired.
* Send a null checksum when initiating a file transfer, which fixes
"files don't match" warnings produced by some versions of WinAIM; add
a compile-time option to actually compute the checksum, which is
slow but necessary when sending to some Mac clients.
* Don't allow sending files to oneself, because it causes all kinds of
subtle problems and it's not useful.
* Don't crash when there is an error writing to the output file when
receiving.
From: "William T. Mahan" <wtm2@duke.edu>
This patch 2 of 3, which applies on top of the first, adds support for
reverse connections for Oscar File Transfer, the lack of which has
been the biggest complaint so far. Reverse connections are used by
newer AIM clients when there is difficulty verifying the IP of the
sender.
From: "William T. Mahan" <wtm2@duke.edu>
This patch 3 of 3, which applies on top of the first 2, removes the
alarm() and sigaction() calls that were added by my original FT patch
to detect transfer timeouts. Besides apparently not working on
Windows, they involved a lot of ugly code to handle a special case.
My new approach is to add destructors that can called when SNACs are
freed; a timeout is detected when a request SNAC is cleaned up before
the transfer is accepted. Although this touches several files, it is
more generic than the old method. I tried to implement this in an
unintrusive manner, so that there is little preformance penalty for
SNACs that do not use destructors.
My first two patches should work fine without this. If there are any
objections to the third patch, I ask that the first two patches be
applied, in which case I will set up a SourceForge page for this one.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 19 Oct 2002 05:22:30 +0000 |
parents | cd938f18f3f8 |
children | 07a3d1fae88f |
rev | line source |
---|---|
1803 | 1 #define GAIM_PLUGINS |
2 #include "gaim.h" | |
3 #include <sys/stat.h> | |
4 #include <sys/types.h> | |
5 #include <unistd.h> | |
6 | |
7 #define ANY_MAIL 0x01 | |
8 #define UNREAD_MAIL 0x02 | |
9 #define NEW_MAIL 0x04 | |
10 | |
11 static guint32 timer = 0; | |
12 static GtkWidget *mail = NULL; | |
13 | |
14 static gint check_mail() | |
15 { | |
16 static off_t oldsize = 0; | |
17 gchar *filename; | |
18 off_t newsize; | |
19 struct stat s; | |
20 gint ret = 0; | |
21 | |
22 filename = g_getenv("MAIL"); | |
23 if (!filename) | |
24 filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
25 else | |
26 filename = g_strdup(filename); | |
27 | |
28 if (stat(filename, &s) < 0) { | |
29 g_free(filename); | |
30 return -1; | |
31 } | |
32 | |
33 newsize = s.st_size; | |
34 if (newsize) ret |= ANY_MAIL; | |
35 if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; | |
36 if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; | |
37 oldsize = newsize; | |
38 | |
39 g_free(filename); | |
40 | |
41 return ret; | |
42 } | |
43 | |
44 static void maildes() | |
45 { | |
46 mail = NULL; | |
47 } | |
48 | |
49 static gboolean check_timeout(gpointer data) | |
50 { | |
51 gint count = check_mail(); | |
52 | |
53 if (count == -1) | |
54 return FALSE; | |
55 | |
56 if (!blist) | |
57 return TRUE; | |
58 | |
59 if (!mail) { | |
60 /* guess we better build it then :P */ | |
61 GList *tmp = gtk_container_children(GTK_CONTAINER(blist)); | |
62 GtkWidget *vbox2 = (GtkWidget *)tmp->data; | |
63 | |
64 mail = gtk_label_new("No mail messages."); | |
65 gtk_box_pack_start(GTK_BOX(vbox2), mail, FALSE, FALSE, 0); | |
66 gtk_box_reorder_child(GTK_BOX(vbox2), mail, 1); | |
67 gtk_signal_connect(GTK_OBJECT(mail), "destroy", GTK_SIGNAL_FUNC(maildes), NULL); | |
68 gtk_widget_show(mail); | |
69 } | |
70 | |
71 if (count & NEW_MAIL) | |
3060 | 72 play_sound(SND_POUNCE_DEFAULT); |
1803 | 73 |
74 if (count & UNREAD_MAIL) | |
75 gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
76 else if (count & ANY_MAIL) | |
77 gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
78 else | |
79 gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
80 | |
81 return TRUE; | |
82 } | |
83 | |
84 static void mail_signon(struct gaim_connection *gc) | |
85 { | |
86 if (blist && !timer) | |
87 timer = gtk_timeout_add(2000, check_timeout, NULL); | |
88 } | |
89 | |
90 static void mail_signoff(struct gaim_connection *gc) | |
91 { | |
2259
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
92 if (!blist && timer) { |
1803 | 93 gtk_timeout_remove(timer); |
2259
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
94 timer = 0; |
866bf3ced1bc
[gaim-migrate @ 2269]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1804
diff
changeset
|
95 } |
1803 | 96 } |
97 | |
98 char *gaim_plugin_init(GModule *m) | |
99 { | |
100 if (!check_timeout(NULL)) | |
101 return "Could not read $MAIL or /var/spool/mail/$USER"; | |
102 if (blist) | |
103 timer = gtk_timeout_add(2000, check_timeout, NULL); | |
104 gaim_signal_connect(m, event_signon, mail_signon, NULL); | |
105 gaim_signal_connect(m, event_signoff, mail_signoff, NULL); | |
106 return NULL; | |
107 } | |
108 | |
109 void gaim_plugin_remove() | |
110 { | |
111 if (timer) | |
112 gtk_timeout_remove(timer); | |
113 timer = 0; | |
114 if (mail) | |
115 gtk_widget_destroy(mail); | |
116 mail = NULL; | |
117 } | |
118 | |
3551 | 119 struct gaim_plugin_description desc; |
120 struct gaim_plugin_description *gaim_plugin_desc() { | |
121 desc.api_version = PLUGIN_API_VERSION; | |
122 desc.name = g_strdup("Mail Checker"); | |
123 desc.version = g_strdup(VERSION); | |
124 desc.description = g_strdup("Checks for new local mail."); | |
125 desc.authors = g_strdup("Eric Warmehoven <eric@warmenhoven.org>"); | |
126 desc.url = g_strdup(WEBSITE); | |
127 return &desc; | |
128 } | |
129 | |
1803 | 130 char *name() |
131 { | |
132 return "Mail Check"; | |
133 } | |
134 | |
135 char *description() | |
136 { | |
137 return "Checks for new local mail"; | |
138 } |