src/mn-system-vfs-mailbox.gob (2924B) - raw
1 /* 2 * Mail Notification 3 * Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 %headertop{ 21 #include "mn-vfs-mailbox.h" 22 %} 23 24 %{ 25 #include <glib/gi18n.h> 26 #include "mn-stock.h" 27 #include "mn-mailbox-private.h" 28 %} 29 30 class MN:System:VFS:Mailbox from MN:VFS:Mailbox 31 { 32 class_init (class) 33 { 34 MN_MAILBOX_CLASS(class)->type = "system-vfs"; 35 } 36 37 override (MN:Mailbox) void 38 seal (MNMailbox *mailbox) 39 { 40 mn_mailbox_set_stock_id(mailbox, MN_STOCK_SYSTEM_MAILBOX); 41 42 MN_VFS_MAILBOX(mailbox)->uri = g_strdup(self_get_uri()); 43 44 mailbox->runtime_name = g_strdup(_("System mailbox")); 45 46 PARENT_HANDLER(mailbox); 47 } 48 49 override (MN:Mailbox) MNMailbox * 50 parse_uri (MNMailbox *dummy, const char *uri) 51 { 52 const char *system_uri; 53 MNMailbox *mailbox = NULL; 54 55 system_uri = self_get_uri(); 56 if (system_uri && gnome_vfs_uris_match(uri, system_uri)) 57 mailbox = mn_mailbox_new("system-vfs", NULL); 58 59 return mailbox; 60 } 61 62 override (MN:Mailbox) void 63 check (MNMailbox *mailbox) 64 { 65 if (MN_VFS_MAILBOX(mailbox)->uri) 66 { 67 PARENT_HANDLER(mailbox); 68 } 69 else 70 { 71 mn_mailbox_set_error(mailbox, _("system mailbox not found")); 72 mn_mailbox_set_poll(mailbox, FALSE); /* disable the mailbox */ 73 } 74 } 75 76 public const char * 77 get_uri (void) 78 { 79 static char *global_uri = NULL; 80 G_LOCK_DEFINE_STATIC(global_uri); 81 const char *uri; 82 83 G_LOCK(global_uri); 84 if (! global_uri) 85 { 86 const char *mail = g_getenv("MAIL"); 87 88 if (mail && g_path_is_absolute(mail) && g_file_test(mail, G_FILE_TEST_EXISTS)) 89 global_uri = gnome_vfs_get_uri_from_local_path(mail); 90 91 if (! global_uri) /* no MAIL or invalid contents */ 92 { 93 const char *username = g_get_user_name(); 94 static const char *spool_paths[] = { "/var/spool/mail", "/var/mail" }; 95 int i; 96 97 for (i = 0; i < G_N_ELEMENTS(spool_paths); i++) 98 { 99 char *path; 100 101 path = g_build_filename(spool_paths[i], username, NULL); 102 if (g_file_test(path, G_FILE_TEST_EXISTS)) 103 global_uri = gnome_vfs_get_uri_from_local_path(path); 104 g_free(path); 105 106 if (global_uri) 107 break; 108 } 109 } 110 } 111 uri = global_uri; 112 G_UNLOCK(global_uri); 113 114 return uri; 115 } 116 }