source: messagelist.c @ fa4562c

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since fa4562c was d43edd2, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Death to RCS keywords. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 2.3 KB
Line 
1#include "owl.h"
2#include <stdlib.h>
3#include <string.h>
4
5int owl_messagelist_create(owl_messagelist *ml)
6{
7  owl_list_create(&(ml->list));
8  return(0);
9}
10
11int owl_messagelist_get_size(owl_messagelist *ml)
12{
13  return(owl_list_get_size(&(ml->list)));
14}
15
16void *owl_messagelist_get_element(owl_messagelist *ml, int n)
17{
18  return(owl_list_get_element(&(ml->list), n));
19}
20
21owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int target_id)
22{
23  /* return the message with id == 'id'.  If it doesn't exist return NULL. */
24  int first, last, mid, msg_id;
25  owl_message *m;
26
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    }
40  }
41  return(NULL);
42}
43
44int owl_messagelist_append_element(owl_messagelist *ml, void *element)
45{
46  return(owl_list_append_element(&(ml->list), element));
47}
48
49/* do we really still want this? */
50int owl_messagelist_delete_element(owl_messagelist *ml, int n)
51{
52  /* mark a message as deleted */
53  owl_message_mark_delete(owl_list_get_element(&(ml->list), n));
54  return(0);
55}
56
57int owl_messagelist_undelete_element(owl_messagelist *ml, int n)
58{
59  /* mark a message as deleted */
60  owl_message_unmark_delete(owl_list_get_element(&(ml->list), n));
61  return(0);
62}
63
64int owl_messagelist_expunge(owl_messagelist *ml)
65{
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}
91
92void 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}
Note: See TracBrowser for help on using the repository browser.