1 /* Notification plugin for Claws Mail
2 * Copyright (C) 2005-2007 Holger Berndt
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # include "claws-features.h"
23 #ifdef NOTIFICATION_COMMAND
27 #include "common/utils.h"
29 #include "notification_command.h"
30 #include "notification_prefs.h"
31 #include "notification_foldercheck.h"
36 } NotificationCommand
;
38 static gboolean
command_timeout_fun(gpointer data
);
40 static NotificationCommand command
;
42 G_LOCK_DEFINE_STATIC(command
);
44 void notification_command_msg(MsgInfo
*msginfo
)
47 gsize by_read
= 0, by_written
= 0;
49 if(!msginfo
|| !notify_config
.command_enabled
|| !MSG_IS_NEW(msginfo
->flags
))
52 if(!notify_config
.command_enabled
|| !MSG_IS_NEW(msginfo
->flags
))
55 if(notify_config
.command_folder_specific
) {
59 gboolean found
= FALSE
;
61 if(!(msginfo
->folder
))
64 identifier
= folder_item_get_identifier(msginfo
->folder
);
67 notification_register_folder_specific_list(COMMAND_SPECIFIC_FOLDER_ID_STR
);
68 list
= notification_foldercheck_get_list(id
);
69 for(; (list
!= NULL
) && !found
; list
= g_slist_next(list
)) {
70 gchar
*list_identifier
;
71 FolderItem
*list_item
= (FolderItem
*) list
->data
;
73 list_identifier
= folder_item_get_identifier(list_item
);
74 if(!g_strcmp0(list_identifier
, identifier
))
77 g_free(list_identifier
);
83 } /* folder specific */
85 buf
= g_strdup(notify_config
.command_line
);
89 if(!command
.blocked
) {
91 command
.blocked
= TRUE
;
92 ret_str
= g_locale_from_utf8(buf
,strlen(buf
),&by_read
,&by_written
,NULL
);
93 if(ret_str
&& by_written
) {
97 execute_command_line(buf
, TRUE
, NULL
);
101 /* block further execution for some time,
102 no matter if it was blocked or not */
103 if(command
.timeout_id
)
104 g_source_remove(command
.timeout_id
);
105 command
.timeout_id
= g_timeout_add(notify_config
.command_timeout
,
106 command_timeout_fun
, NULL
);
110 static gboolean
command_timeout_fun(gpointer data
)
113 command
.timeout_id
= 0;
114 command
.blocked
= FALSE
;
119 #endif /* NOTIFICATION_COMMAND */