source: messagelist.c @ 488ebf6

owl
Last change on this file since 488ebf6 was fa00c5c, checked in by James M. Kretchmar <kretch@mit.edu>, 15 years ago
Correct license.
  • Property mode set to 100644
File size: 3.3 KB
Line 
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 branched BarnOwl project, Copyright (c)
22 * 2006-2009 The BarnOwl Developers. All rights reserved.
23 */
24
25#include "owl.h"
26#include <stdlib.h>
27#include <string.h>
28
29static const char fileIdent[] = "$Id$";
30
31int owl_messagelist_create(owl_messagelist *ml)
32{
33  owl_list_create(&(ml->list));
34  return(0);
35}
36
37int owl_messagelist_get_size(owl_messagelist *ml)
38{
39  return(owl_list_get_size(&(ml->list)));
40}
41
42void *owl_messagelist_get_element(owl_messagelist *ml, int n)
43{
44  return(owl_list_get_element(&(ml->list), n));
45}
46
47owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int target_id)
48{
49  /* return the message with id == 'id'.  If it doesn't exist return NULL. */
50  int first, last, mid, msg_id;
51  owl_message *m;
52
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    }
66  }
67  return(NULL);
68}
69
70int owl_messagelist_append_element(owl_messagelist *ml, void *element)
71{
72  return(owl_list_append_element(&(ml->list), element));
73}
74
75/* do we really still want this? */
76int owl_messagelist_delete_element(owl_messagelist *ml, int n)
77{
78  /* mark a message as deleted */
79  owl_message_mark_delete(owl_list_get_element(&(ml->list), n));
80  return(0);
81}
82
83int owl_messagelist_undelete_element(owl_messagelist *ml, int n)
84{
85  /* mark a message as deleted */
86  owl_message_unmark_delete(owl_list_get_element(&(ml->list), n));
87  return(0);
88}
89
90int owl_messagelist_expunge(owl_messagelist *ml)
91{
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}
117
118void 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}
Note: See TracBrowser for help on using the repository browser.