Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
3160d750
...
3160d75010b83bb73df5fc19ddc2b95fdca5f6c9
authored
2007-03-07 19:53:40 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Remove rudimentary header caching
1 parent
100441be
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
329 deletions
libproto/mbox/mbox.c
libproto/mbox/mbox0.h
libproto/mbox/mboxscan.c
libproto/mbox/mbox.c
View file @
3160d75
...
...
@@ -30,31 +30,6 @@
static
void
mbox_destroy
(
mu_mailbox_t
);
/* Below are the headers field-names that we are caching for speed, it is
more or less the list of headers in ENVELOPE command from IMAP.
NOTE: These are indexed with H_.* macros defined in mbox0.h. Keep them
in sync if you add or remove something. */
const
char
*
fhdr_table
[
HDRSIZE
]
=
{
"Bcc"
,
"Cc"
,
"Content-Language"
,
"Content-Transfer-Encoding"
,
"Content-Type"
,
"Date"
,
"From"
,
"In-Reply-To"
,
"Message-ID"
,
"Reference"
,
"Reply-To"
,
"Sender"
,
"Subject"
,
"To"
,
"X-UIDL"
};
/* Mailbox concrete implementation. */
static
int
mbox_open
(
mu_mailbox_t
,
int
);
static
int
mbox_close
(
mu_mailbox_t
);
...
...
@@ -186,11 +161,7 @@ mbox_destroy (mu_mailbox_t mailbox)
mbox_message_t
mum
=
mud
->
umessages
[
i
];
if
(
mum
)
{
size_t
j
;
mu_message_destroy
(
&
(
mum
->
message
),
mum
);
for
(
j
=
0
;
j
<
HDRSIZE
;
j
++
)
if
(
mum
->
fhdr
[
j
])
free
(
mum
->
fhdr
[
j
]);
free
(
mum
);
}
}
...
...
@@ -299,11 +270,7 @@ mbox_close (mu_mailbox_t mailbox)
/* Destroy the attach messages. */
if
(
mum
)
{
size_t
j
;
mu_message_destroy
(
&
(
mum
->
message
),
mum
);
for
(
j
=
0
;
j
<
HDRSIZE
;
j
++
)
if
(
mum
->
fhdr
[
j
])
free
(
mum
->
fhdr
[
j
]);
free
(
mum
);
}
}
...
...
@@ -768,12 +735,6 @@ mbox_expunge0 (mu_mailbox_t mailbox, int remove_deleted)
mum->body = mum->body_end = 0;
mum->header_lines = mum->body_lines = 0;
#endif
for
(
i
=
0
;
i
<
HDRSIZE
;
i
++
)
if
(
mum
->
fhdr
[
i
])
{
free
(
mum
->
fhdr
[
i
]);
mum
->
fhdr
[
i
]
=
NULL
;
}
memset
(
mum
,
0
,
sizeof
(
*
mum
));
/* We are not free()ing the useless mum, but instead
we put it back in the pool, to be reuse. */
...
...
@@ -785,24 +746,12 @@ mbox_expunge0 (mu_mailbox_t mailbox, int remove_deleted)
}
else
{
for
(
i
=
0
;
i
<
HDRSIZE
;
i
++
)
if
(
mum
->
fhdr
[
i
])
{
free
(
mum
->
fhdr
[
i
]);
mum
->
fhdr
[
i
]
=
NULL
;
}
memset
(
mum
,
0
,
sizeof
(
*
mum
));
}
}
mum
->
header_from
=
mum
->
header_from_end
=
0
;
mum
->
body
=
mum
->
body_end
=
0
;
mum
->
header_lines
=
mum
->
body_lines
=
0
;
for
(
i
=
0
;
i
<
HDRSIZE
;
i
++
)
if
(
mum
->
fhdr
[
i
])
{
free
(
mum
->
fhdr
[
i
]);
mum
->
fhdr
[
i
]
=
NULL
;
}
}
mu_monitor_unlock
(
mailbox
->
monitor
);
/* This is should reset the messages_count, the last argument 0 means
...
...
@@ -964,58 +913,11 @@ mbox_header_fill (mu_header_t header, char *buffer, size_t len,
{
mu_message_t
msg
=
mu_header_get_owner
(
header
);
mbox_message_t
mum
=
mu_message_get_owner
(
msg
);
size_t
j
;
/* Since we are filling the header there is no need for the cache headers
discard them. */
for
(
j
=
0
;
j
<
HDRSIZE
;
j
++
)
{
if
(
mum
->
fhdr
[
j
])
{
free
(
mum
->
fhdr
[
j
]);
mum
->
fhdr
[
j
]
=
NULL
;
}
}
return
mbox_readstream
(
mum
,
buffer
,
len
,
off
,
pnread
,
0
,
mum
->
header_from_end
,
mum
->
body
);
}
static
int
mbox_header_get_fvalue
(
mu_header_t
header
,
const
char
*
name
,
char
*
buffer
,
size_t
buflen
,
size_t
*
pnread
)
{
size_t
i
,
fv_len
=
0
;
mu_message_t
msg
=
mu_header_get_owner
(
header
);
mbox_message_t
mum
=
mu_message_get_owner
(
msg
);
int
err
=
MU_ERR_NOENT
;
for
(
i
=
0
;
i
<
HDRSIZE
;
i
++
)
{
if
(
*
name
==
*
(
fhdr_table
[
i
])
&&
strcasecmp
(
fhdr_table
[
i
],
name
)
==
0
)
{
if
(
mum
->
fhdr
[
i
])
{
fv_len
=
strlen
(
mum
->
fhdr
[
i
]);
if
(
buffer
&&
buflen
>
0
)
{
/* For the null. */
buflen
--
;
fv_len
=
(
fv_len
<
buflen
)
?
fv_len
:
buflen
;
memcpy
(
buffer
,
mum
->
fhdr
[
i
],
fv_len
);
buffer
[
fv_len
]
=
'\0'
;
}
err
=
0
;
}
else
err
=
MU_ERR_NOENT
;
break
;
}
}
if
(
pnread
)
*
pnread
=
fv_len
;
return
err
;
}
static
int
mbox_header_size
(
mu_header_t
header
,
size_t
*
psize
)
{
mu_message_t
msg
=
mu_header_get_owner
(
header
);
...
...
@@ -1218,7 +1120,6 @@ mbox_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg)
return
status
;
}
mu_header_set_fill
(
header
,
mbox_header_fill
,
msg
);
mu_header_set_get_fvalue
(
header
,
mbox_header_get_fvalue
,
msg
);
mu_header_set_size
(
header
,
mbox_header_size
,
msg
);
mu_header_set_lines
(
header
,
mbox_header_lines
,
msg
);
mu_message_set_header
(
msg
,
header
,
mum
);
...
...
libproto/mbox/mbox0.h
View file @
3160d75
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2003, 2005
Free Software Foundation, Inc.
Copyright (C) 2003, 2005
, 2007
Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
...
...
@@ -66,24 +66,6 @@
#include <mailutils/stream.h>
#include <mailutils/url.h>
#define H_BCC 0
#define H_CC 1
#define H_CONTENT_LANGUAGE 2
#define H_CONTENT_TRANSFER_ENCODING 3
#define H_CONTENT_TYPE 4
#define H_DATE 5
#define H_FROM 6
#define H_IN_REPLY_TO 7
#define H_MESSAGE_ID 8
#define H_REFERENCE 9
#define H_REPLY_TO 10
#define H_SENDER 11
#define H_SUBJECT 12
#define H_TO 13
#define H_X_UIDL 14
#define HDRSIZE 15
struct
_mbox_message
;
struct
_mbox_data
;
...
...
@@ -100,11 +82,6 @@ struct _mbox_message
off_t
body
;
off_t
body_end
;
/* Fast header retrieve, we save here the most common headers. This will
speed the header search. The entire headers are copied, when modified,
by the mu_header_t object, we do not have to worry about updating them. */
char
*
fhdr
[
HDRSIZE
];
size_t
uid
;
/* IMAP uid. */
int
attr_flags
;
/* The attr_flags contains the "Status:" attribute */
...
...
libproto/mbox/mboxscan.c
View file @
3160d75
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2003, 2005,
2007 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
...
...
@@ -404,100 +405,6 @@ do { \
i = 10 * i + (*a - '0'); \
} while (0)
/* Save/concatenate the field-value in the fast header(fhd) field.
Notice that care is taken to preserve the intermediate newlines
in the folded headers. However, the final newline is always
removed. */
#define FAST_HEADER(field,buf,n) \
do { \
int i = 0; \
char *s = field; \
char *p = buf; \
if (s) \
while (*s++) i++; \
else \
{ \
p = memchr (buf, ':', n); \
if (p) p++; \
} \
if (p) \
{ \
int l; \
char *tmp; \
buf[n - 1] = '\0'; \
if (!field) \
SKIPSPACE(p); \
l = n - (p - buf); \
tmp = realloc (field, (l + (i ? i + 1 : 0) + 1) * sizeof (char)); \
if (tmp) \
{ \
field = tmp; \
if (i) field[i++] = '\n'; \
memcpy (field + i, p, l); \
} \
} \
} while (0)
#define FAST_H_BCC(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_BCC],buf,n); \
save_field = &(mum->fhdr[H_BCC])
#define FAST_H_CC(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_CC],buf,n); \
save_field = &(mum->fhdr[H_CC])
#define FAST_H_CONTENT_LANGUAGE(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_CONTENT_LANGUAGE],buf,n); \
save_field = &(mum->fhdr[H_CONTENT_LANGUAGE])
#define FAST_H_CONTENT_TRANSFER_ENCODING(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_CONTENT_TRANSFER_ENCODING],buf,n); \
save_field = &(mum->fhdr[H_CONTENT_TRANSFER_ENCODING])
#define FAST_H_CONTENT_TYPE(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_CONTENT_TYPE],buf,n); \
save_field = &(mum->fhdr[H_CONTENT_TYPE])
#define FAST_H_DATE(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_DATE],buf,n); \
save_field = &(mum->fhdr[H_DATE])
#define FAST_H_FROM(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_FROM],buf,n); \
save_field = &(mum->fhdr[H_FROM])
#define FAST_H_IN_REPLY_TO(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_IN_REPLY_TO],buf,n); \
save_field = &(mum->fhdr[H_IN_REPLY_TO])
#define FAST_H_MESSAGE_ID(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_MESSAGE_ID],buf,n); \
save_field = &(mum->fhdr[H_MESSAGE_ID])
#define FAST_H_REFERENCE(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_REFERENCE],buf,n); \
save_field = &(mum->fhdr[H_REFERENCE])
#define FAST_H_REPLY_TO(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_REPLY_TO],buf,n); \
save_field = &(mum->fhdr[H_REPLY_TO])
#define FAST_H_SENDER(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_SENDER],buf,n); \
save_field = &(mum->fhdr[H_SENDER])
#define FAST_H_SUBJECT(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_SUBJECT],buf,n); \
save_field = &(mum->fhdr[H_SUBJECT])
#define FAST_H_TO(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_TO],buf,n); \
save_field = &(mum->fhdr[H_TO])
#define FAST_H_X_UIDL(mum,save_field,buf,n) \
FAST_HEADER(mum->fhdr[H_X_UIDL],buf,n); \
save_field = &(mum->fhdr[H_X_UIDL])
/* Notifications ADD_MESG. */
#define DISPATCH_ADD_MSG(mbox,mud) \
do \
...
...
@@ -585,7 +492,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
int
newline
;
size_t
n
=
0
;
mu_stream_t
stream
;
char
**
sfield
=
NULL
;
size_t
min_uid
=
0
;
int
zn
,
isfrom
=
0
;
char
*
temp
;
...
...
@@ -629,18 +535,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
else
mud
->
messages_count
=
0
;
#if 0
{
size_t j, k;
for (j = 0; j < mud->umessages_count; j++)
{
mum = mud->umessages[j];
for (k = 0; k < HDRSIZE; k++)
if (mum->fhdr[k])
free (mum->fhdr[k]);
}
}
#endif
newline
=
1
;
errno
=
lines
=
inheader
=
inbody
=
0
;
...
...
@@ -667,7 +561,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
/* New message. */
if
(
isfrom
)
{
size_t
j
;
/* Signal the end of the body. */
if
(
mum
&&
!
mum
->
body_end
)
{
...
...
@@ -697,13 +590,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
mum
->
body_end
=
mum
->
body
=
0
;
mum
->
attr_flags
=
0
;
lines
=
0
;
sfield
=
NULL
;
for
(
j
=
0
;
j
<
HDRSIZE
;
j
++
)
if
(
mum
->
fhdr
[
j
])
{
free
(
mum
->
fhdr
[
j
]);
mum
->
fhdr
[
j
]
=
NULL
;
}
}
else
if
(
ISSTATUS
(
buf
))
{
...
...
@@ -711,96 +597,6 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
ATTRIBUTE_SET
(
buf
,
mum
,
'o'
,
'O'
,
MU_ATTRIBUTE_SEEN
);
ATTRIBUTE_SET
(
buf
,
mum
,
'a'
,
'A'
,
MU_ATTRIBUTE_ANSWERED
);
ATTRIBUTE_SET
(
buf
,
mum
,
'd'
,
'D'
,
MU_ATTRIBUTE_DELETED
);
sfield
=
NULL
;
}
else
if
(
ISBCC
(
buf
))
{
FAST_H_BCC
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISCC
(
buf
))
{
FAST_H_CC
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISCONTENT_LANGUAGE
(
buf
))
{
FAST_H_CONTENT_LANGUAGE
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISCONTENT_TRANSFER_ENCODING
(
buf
))
{
FAST_H_CONTENT_TRANSFER_ENCODING
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISCONTENT_TYPE
(
buf
))
{
FAST_H_CONTENT_TYPE
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISDATE
(
buf
))
{
FAST_H_DATE
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISFROM
(
buf
))
{
FAST_H_FROM
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISIN_REPLY_TO
(
buf
))
{
FAST_H_IN_REPLY_TO
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISMESSAGE_ID
(
buf
))
{
FAST_H_MESSAGE_ID
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISREFERENCE
(
buf
))
{
FAST_H_REFERENCE
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISREPLY_TO
(
buf
))
{
FAST_H_REPLY_TO
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISSENDER
(
buf
))
{
FAST_H_SENDER
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISSUBJECT
(
buf
))
{
FAST_H_SUBJECT
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISTO
(
buf
))
{
FAST_H_TO
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISX_UIDL
(
buf
))
{
FAST_H_X_UIDL
(
mum
,
sfield
,
buf
,
n
);
}
else
if
(
ISX_IMAPBASE
(
buf
))
{
char
*
s
=
memchr
(
buf
,
':'
,
n
);
if
(
s
)
{
s
++
;
ATOI
(
s
,
mud
->
uidvalidity
);
ATOI
(
s
,
mud
->
uidnext
);
}
}
else
if
(
ISX_UID
(
buf
))
{
char
*
s
=
memchr
(
buf
,
':'
,
n
);
if
(
s
)
{
s
++
;
ATOI
(
s
,
mum
->
uid
);
}
}
else
if
(
sfield
&&
(
buf
[
0
]
==
' '
||
buf
[
0
]
==
'\t'
))
{
char
*
save
=
*
sfield
;
FAST_HEADER
(
save
,
buf
,
n
);
*
sfield
=
save
;
}
else
{
sfield
=
NULL
;
}
}
...
...
Please
register
or
sign in
to post a comment