Cross Reference:
xref
: /
vbox
/
src
/
VBox
/
VMM
/
VMMR3
/
STAM.cpp
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
index-copy.c revision 8bd7404367404f38cc36c1edb0872915c4d06bf1
1516
N/A
/* Copyright (C) 2002 Timo Sirainen */
39
N/A
39
N/A
#
include
"
lib.h
"
39
N/A
#
include
"
ibuffer.h
"
39
N/A
#
include
"
mail-custom-flags.h
"
39
N/A
#
include
"
index-storage.h
"
39
N/A
#
include
"
index-messageset.h
"
39
N/A
39
N/A
#
include
<
unistd.h
>
39
N/A
39
N/A
typedef
struct
{
39
N/A
Mailbox
*
dest
;
39
N/A
const
char
**
custom_flags
;
39
N/A
int
copy_inside_mailbox
;
39
N/A
}
CopyContext
;
39
N/A
39
N/A
static
int
copy_func
(
MailIndex
*
index
,
MailIndexRecord
*
rec
,
39
N/A
unsigned
int
client_seq
__attr_unused__
,
39
N/A
unsigned
int
idx_seq
__attr_unused__
,
void
*
context
)
39
N/A
{
39
N/A
CopyContext
*
ctx
=
context
;
926
N/A
IndexMailbox
*
dest_ibox
=
NULL
;
926
N/A
IBuffer
*
inbuf
;
3312
N/A
time_t
internal_date
;
926
N/A
int
failed
,
deleted
;
39
N/A
3339
N/A
inbuf
=
index
->
open_mail
(
index
,
rec
, &
internal_date
, &
deleted
);
2453
N/A
if
(
inbuf
==
NULL
)
3194
N/A
return
FALSE
;
3194
N/A
342
N/A
if
(
ctx
->
copy_inside_mailbox
) {
3041
N/A
/* kludgy.. */
1516
N/A
dest_ibox
= (
IndexMailbox
*)
ctx
->
dest
;
1636
N/A
dest_ibox
->
delay_save_unlocking
=
TRUE
;
3041
N/A
}
3234
N/A
1386
N/A
/* save it in destination mailbox */
3234
N/A
failed
= !
ctx
->
dest
->
save
(
ctx
->
dest
,
rec
->
msg_flags
,
2639
N/A
ctx
->
custom_flags
,
internal_date
, 0,
3234
N/A
inbuf
,
inbuf
->
v_limit
);
39
N/A
51
N/A
if
(
ctx
->
copy_inside_mailbox
)
2073
N/A
dest_ibox
->
delay_save_unlocking
=
FALSE
;
2910
N/A
3110
N/A
i_buffer_unref
(
inbuf
);
2144
N/A
return
!
failed
;
1066
N/A
}
1231
N/A
2453
N/A
int
index_storage_copy
(
Mailbox
*
box
,
Mailbox
*
destbox
,
1352
N/A
const
char
*
messageset
,
int
uidset
)
1890
N/A
{
296
N/A
IndexMailbox
*
ibox
= (
IndexMailbox
*)
box
;
2876
N/A
CopyContext
ctx
;
39
N/A
MailLockType
lock_type
;
3041
N/A
int
failed
;
3041
N/A
3041
N/A
if
(
destbox
->
readonly
) {
3041
N/A
mail_storage_set_error
(
box
->
storage
,
3041
N/A
"Destination mailbox is read-only"
);
3041
N/A
return
FALSE
;
3041
N/A
}
3041
N/A
3041
N/A
ctx
.
copy_inside_mailbox
=
3234
N/A
destbox
->
storage
==
box
->
storage
&&
3041
N/A
strcmp
(
destbox
->
name
,
box
->
name
) == 0;
3041
N/A
3041
N/A
if
(
ctx
.
copy_inside_mailbox
) {
3041
N/A
/* copying inside same mailbox */
3041
N/A
if
(!
ibox
->
index
->
set_lock
(
ibox
->
index
,
MAIL_LOCK_EXCLUSIVE
))
3041
N/A
return
mail_storage_set_index_error
(
ibox
);
3041
N/A
3041
N/A
lock_type
=
MAIL_LOCK_EXCLUSIVE
;
3041
N/A
}
else
{
3041
N/A
lock_type
=
MAIL_LOCK_SHARED
;
3041
N/A
}
3041
N/A
3234
N/A
if
(!
index_storage_sync_and_lock
(
ibox
,
TRUE
,
lock_type
))
3041
N/A
return
FALSE
;
3041
N/A
3041
N/A
ctx
.
custom_flags
=
3041
N/A
mail_custom_flags_list_get
(
ibox
->
index
->
custom_flags
);
3041
N/A
ctx
.
dest
=
destbox
;
3041
N/A
3041
N/A
failed
=
index_messageset_foreach
(
ibox
,
messageset
,
uidset
,
3041
N/A
copy_func
, &
ctx
) <= 0;
2690
N/A
2690
N/A
if
(!
ibox
->
index
->
set_lock
(
ibox
->
index
,
MAIL_LOCK_UNLOCK
))
2690
N/A
return
mail_storage_set_index_error
(
ibox
);
2690
N/A
2690
N/A
return
!
failed
;
2690
N/A
}
2690
N/A