source: messagelist.c @ 7d4fbcd

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7d4fbcd was 7d4fbcd, checked in by James M. Kretchmar <kretch@mit.edu>, 18 years ago
Initial check in
  • Property mode set to 100644
File size: 2.1 KB
Line 
1#include "owl.h"
2#include <stdlib.h>
3#include <string.h>
4
5int owl_messagelist_create(owl_messagelist *ml) {
6  owl_list_create(&(ml->list));
7  return(0);
8}
9
10int owl_messagelist_get_size(owl_messagelist *ml) {
11  return(owl_list_get_size(&(ml->list)));
12}
13
14void *owl_messagelist_get_element(owl_messagelist *ml, int n) {
15  return(owl_list_get_element(&(ml->list), n));
16}
17
18owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int id) {
19  /* return the message with id == 'id'.  If it doesn't exist return NULL. */
20  /* we could make this much more efficient at some point */
21  int i, j;
22  owl_message *m;
23
24  j=owl_list_get_size(&(ml->list));
25  for (i=0; i<j; i++) {
26    m=owl_list_get_element(&(ml->list), i);
27    if (owl_message_get_id(m)==id) return(m);
28
29    /* the message id's have to be sequential.  If we've passed the
30       one we're looking for just bail */
31    if (owl_message_get_id(m) > id) return(NULL);
32  }
33  return(NULL);
34}
35
36int owl_messagelist_append_element(owl_messagelist *ml, void *element) {
37  return(owl_list_append_element(&(ml->list), element));
38}
39
40/* do we really still want this? */
41int owl_messagelist_delete_element(owl_messagelist *ml, int n) {
42  /* mark a message as deleted */
43  owl_message_mark_delete(owl_list_get_element(&(ml->list), n));
44  return(0);
45}
46
47int owl_messagelist_undelete_element(owl_messagelist *ml, int n) {
48  /* mark a message as deleted */
49  owl_message_unmark_delete(owl_list_get_element(&(ml->list), n));
50  return(0);
51}
52
53int owl_messagelist_expunge(owl_messagelist *ml) {
54  /* expunge deleted messages */
55  int i, j;
56  owl_list newlist;
57  owl_message *m;
58
59  owl_list_create(&newlist);
60  /*create a new list without messages marked as deleted */
61  j=owl_list_get_size(&(ml->list));
62  for (i=0; i<j; i++) {
63    m=owl_list_get_element(&(ml->list), i);
64    if (owl_message_is_delete(m)) {
65      owl_message_free(m);
66    } else {
67      owl_list_append_element(&newlist, m);
68    }
69  }
70
71  /* free the old list */
72  owl_list_free_simple(&(ml->list));
73
74  /* copy the new list to the old list */
75  memcpy(&(ml->list), &newlist, sizeof(owl_list));
76
77  return(0);
78}
Note: See TracBrowser for help on using the repository browser.