[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <string.h> |
---|
| 4 | |
---|
[bd3f232] | 5 | int owl_messagelist_create(owl_messagelist *ml) |
---|
| 6 | { |
---|
[7d4fbcd] | 7 | owl_list_create(&(ml->list)); |
---|
| 8 | return(0); |
---|
| 9 | } |
---|
| 10 | |
---|
[bd3f232] | 11 | int owl_messagelist_get_size(owl_messagelist *ml) |
---|
| 12 | { |
---|
[7d4fbcd] | 13 | return(owl_list_get_size(&(ml->list))); |
---|
| 14 | } |
---|
| 15 | |
---|
[bd3f232] | 16 | void *owl_messagelist_get_element(owl_messagelist *ml, int n) |
---|
| 17 | { |
---|
[7d4fbcd] | 18 | return(owl_list_get_element(&(ml->list), n)); |
---|
| 19 | } |
---|
| 20 | |
---|
[0c8ab5e] | 21 | owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int target_id) |
---|
[bd3f232] | 22 | { |
---|
[7d4fbcd] | 23 | /* return the message with id == 'id'. If it doesn't exist return NULL. */ |
---|
[0c8ab5e] | 24 | int first, last, mid, msg_id; |
---|
[7d4fbcd] | 25 | owl_message *m; |
---|
| 26 | |
---|
[0c8ab5e] | 27 | first = 0; |
---|
| 28 | last = owl_list_get_size(&(ml->list)) - 1; |
---|
| 29 | while (first <= last) { |
---|
| 30 | mid = (first + last) / 2; |
---|
| 31 | m = owl_list_get_element(&(ml->list), mid); |
---|
| 32 | msg_id = owl_message_get_id(m); |
---|
| 33 | if (msg_id == target_id) { |
---|
| 34 | return(m); |
---|
| 35 | } else if (msg_id < target_id) { |
---|
| 36 | first = mid + 1; |
---|
| 37 | } else { |
---|
| 38 | last = mid - 1; |
---|
| 39 | } |
---|
[7d4fbcd] | 40 | } |
---|
| 41 | return(NULL); |
---|
| 42 | } |
---|
| 43 | |
---|
[bd3f232] | 44 | int owl_messagelist_append_element(owl_messagelist *ml, void *element) |
---|
| 45 | { |
---|
[7d4fbcd] | 46 | return(owl_list_append_element(&(ml->list), element)); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /* do we really still want this? */ |
---|
[bd3f232] | 50 | int owl_messagelist_delete_element(owl_messagelist *ml, int n) |
---|
| 51 | { |
---|
[7d4fbcd] | 52 | /* mark a message as deleted */ |
---|
| 53 | owl_message_mark_delete(owl_list_get_element(&(ml->list), n)); |
---|
| 54 | return(0); |
---|
| 55 | } |
---|
| 56 | |
---|
[bd3f232] | 57 | int owl_messagelist_undelete_element(owl_messagelist *ml, int n) |
---|
| 58 | { |
---|
[7d4fbcd] | 59 | /* mark a message as deleted */ |
---|
| 60 | owl_message_unmark_delete(owl_list_get_element(&(ml->list), n)); |
---|
| 61 | return(0); |
---|
| 62 | } |
---|
| 63 | |
---|
[bd3f232] | 64 | int owl_messagelist_expunge(owl_messagelist *ml) |
---|
| 65 | { |
---|
[7d4fbcd] | 66 | /* expunge deleted messages */ |
---|
| 67 | int i, j; |
---|
| 68 | owl_list newlist; |
---|
| 69 | owl_message *m; |
---|
| 70 | |
---|
| 71 | owl_list_create(&newlist); |
---|
| 72 | /*create a new list without messages marked as deleted */ |
---|
| 73 | j=owl_list_get_size(&(ml->list)); |
---|
| 74 | for (i=0; i<j; i++) { |
---|
| 75 | m=owl_list_get_element(&(ml->list), i); |
---|
| 76 | if (owl_message_is_delete(m)) { |
---|
| 77 | owl_message_free(m); |
---|
| 78 | } else { |
---|
| 79 | owl_list_append_element(&newlist, m); |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /* free the old list */ |
---|
| 84 | owl_list_free_simple(&(ml->list)); |
---|
| 85 | |
---|
| 86 | /* copy the new list to the old list */ |
---|
| 87 | memcpy(&(ml->list), &newlist, sizeof(owl_list)); |
---|
| 88 | |
---|
| 89 | return(0); |
---|
| 90 | } |
---|
[bd3f232] | 91 | |
---|
| 92 | void owl_messagelist_invalidate_formats(owl_messagelist *ml) |
---|
| 93 | { |
---|
| 94 | int i, j; |
---|
| 95 | owl_message *m; |
---|
| 96 | |
---|
| 97 | j=owl_list_get_size(&(ml->list)); |
---|
| 98 | for (i=0; i<j; i++) { |
---|
| 99 | m=owl_list_get_element(&(ml->list), i); |
---|
| 100 | owl_message_invalidate_format(m); |
---|
| 101 | } |
---|
| 102 | } |
---|