[dab82f29] | 1 | /* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar |
---|
| 2 | * |
---|
| 3 | * This file is part of Owl. |
---|
| 4 | * |
---|
| 5 | * Owl 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 | * Owl 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 |
---|
| 16 | * along with Owl. If not, see <http://www.gnu.org/licenses/>. |
---|
| 17 | * |
---|
| 18 | * --------------------------------------------------------------- |
---|
| 19 | * |
---|
| 20 | * As of Owl version 2.1.12 there are patches contributed by |
---|
| 21 | * developers of the the branched BarnOwl project, Copyright (c) |
---|
| 22 | * 2006-2008 The BarnOwl Developers. All rights reserved. |
---|
| 23 | */ |
---|
| 24 | |
---|
[7d4fbcd] | 25 | #include "owl.h" |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | |
---|
[1aee7d9] | 29 | static const char fileIdent[] = "$Id$"; |
---|
| 30 | |
---|
[bd3f232] | 31 | int owl_messagelist_create(owl_messagelist *ml) |
---|
| 32 | { |
---|
[7d4fbcd] | 33 | owl_list_create(&(ml->list)); |
---|
| 34 | return(0); |
---|
| 35 | } |
---|
| 36 | |
---|
[bd3f232] | 37 | int owl_messagelist_get_size(owl_messagelist *ml) |
---|
| 38 | { |
---|
[7d4fbcd] | 39 | return(owl_list_get_size(&(ml->list))); |
---|
| 40 | } |
---|
| 41 | |
---|
[bd3f232] | 42 | void *owl_messagelist_get_element(owl_messagelist *ml, int n) |
---|
| 43 | { |
---|
[7d4fbcd] | 44 | return(owl_list_get_element(&(ml->list), n)); |
---|
| 45 | } |
---|
| 46 | |
---|
[dab82f29] | 47 | owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int target_id) |
---|
[bd3f232] | 48 | { |
---|
[7d4fbcd] | 49 | /* return the message with id == 'id'. If it doesn't exist return NULL. */ |
---|
[dab82f29] | 50 | int first, last, mid, msg_id; |
---|
[7d4fbcd] | 51 | owl_message *m; |
---|
| 52 | |
---|
[dab82f29] | 53 | first = 0; |
---|
| 54 | last = owl_list_get_size(&(ml->list)) - 1; |
---|
| 55 | while (first <= last) { |
---|
| 56 | mid = (first + last) / 2; |
---|
| 57 | m = owl_list_get_element(&(ml->list), mid); |
---|
| 58 | msg_id = owl_message_get_id(m); |
---|
| 59 | if (msg_id == target_id) { |
---|
| 60 | return(m); |
---|
| 61 | } else if (msg_id < target_id) { |
---|
| 62 | first = mid + 1; |
---|
| 63 | } else { |
---|
| 64 | last = mid - 1; |
---|
| 65 | } |
---|
[7d4fbcd] | 66 | } |
---|
| 67 | return(NULL); |
---|
| 68 | } |
---|
| 69 | |
---|
[bd3f232] | 70 | int owl_messagelist_append_element(owl_messagelist *ml, void *element) |
---|
| 71 | { |
---|
[7d4fbcd] | 72 | return(owl_list_append_element(&(ml->list), element)); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | /* do we really still want this? */ |
---|
[bd3f232] | 76 | int owl_messagelist_delete_element(owl_messagelist *ml, int n) |
---|
| 77 | { |
---|
[7d4fbcd] | 78 | /* mark a message as deleted */ |
---|
| 79 | owl_message_mark_delete(owl_list_get_element(&(ml->list), n)); |
---|
| 80 | return(0); |
---|
| 81 | } |
---|
| 82 | |
---|
[bd3f232] | 83 | int owl_messagelist_undelete_element(owl_messagelist *ml, int n) |
---|
| 84 | { |
---|
[7d4fbcd] | 85 | /* mark a message as deleted */ |
---|
| 86 | owl_message_unmark_delete(owl_list_get_element(&(ml->list), n)); |
---|
| 87 | return(0); |
---|
| 88 | } |
---|
| 89 | |
---|
[bd3f232] | 90 | int owl_messagelist_expunge(owl_messagelist *ml) |
---|
| 91 | { |
---|
[7d4fbcd] | 92 | /* expunge deleted messages */ |
---|
| 93 | int i, j; |
---|
| 94 | owl_list newlist; |
---|
| 95 | owl_message *m; |
---|
| 96 | |
---|
| 97 | owl_list_create(&newlist); |
---|
| 98 | /*create a new list without messages marked as deleted */ |
---|
| 99 | j=owl_list_get_size(&(ml->list)); |
---|
| 100 | for (i=0; i<j; i++) { |
---|
| 101 | m=owl_list_get_element(&(ml->list), i); |
---|
| 102 | if (owl_message_is_delete(m)) { |
---|
| 103 | owl_message_free(m); |
---|
| 104 | } else { |
---|
| 105 | owl_list_append_element(&newlist, m); |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /* free the old list */ |
---|
| 110 | owl_list_free_simple(&(ml->list)); |
---|
| 111 | |
---|
| 112 | /* copy the new list to the old list */ |
---|
| 113 | memcpy(&(ml->list), &newlist, sizeof(owl_list)); |
---|
| 114 | |
---|
| 115 | return(0); |
---|
| 116 | } |
---|
[bd3f232] | 117 | |
---|
| 118 | void owl_messagelist_invalidate_formats(owl_messagelist *ml) |
---|
| 119 | { |
---|
| 120 | int i, j; |
---|
| 121 | owl_message *m; |
---|
| 122 | |
---|
| 123 | j=owl_list_get_size(&(ml->list)); |
---|
| 124 | for (i=0; i<j; i++) { |
---|
| 125 | m=owl_list_get_element(&(ml->list), i); |
---|
| 126 | owl_message_invalidate_format(m); |
---|
| 127 | } |
---|
| 128 | } |
---|