@@ -10,7 +10,7 @@ module Imap; end
10
10
module Imap ::Backup
11
11
class Serializer ; end
12
12
13
- # Wraps the Serializer, delaying metadata appends
13
+ # Wraps the Serializer, delaying metadata changes
14
14
class Serializer ::DelayedMetadataSerializer
15
15
extend Forwardable
16
16
@@ -31,7 +31,7 @@ def initialize(serializer:)
31
31
def transaction ( &block )
32
32
tsx . fail_in_transaction! ( :transaction , message : "nested transactions are not supported" )
33
33
34
- tsx . begin ( { metadata : [ ] } ) do
34
+ tsx . begin ( { appends : [ ] , updates : [ ] } ) do
35
35
mbox . transaction do
36
36
block . call
37
37
@@ -42,7 +42,21 @@ def transaction(&block)
42
42
end
43
43
end
44
44
45
- # Appends a message to the mbox file and adds the metadata
45
+ # Sets the folder's UID validity via the serializer
46
+ #
47
+ # @param uid_validity [Integer] the UID validity to apply
48
+ # @raise [RuntimeError] if called inside a transaction
49
+ # @return [void]
50
+ def apply_uid_validity ( uid_validity )
51
+ tsx . fail_in_transaction! (
52
+ :transaction ,
53
+ message : "UID validity cannot be changed in a transaction"
54
+ )
55
+
56
+ serializer . apply_uid_validity ( uid_validity )
57
+ end
58
+
59
+ # Appends a message to the mbox file and adds the appended message's metadata
46
60
# to the transaction
47
61
#
48
62
# @param uid [Integer] the UID of the message
@@ -53,20 +67,34 @@ def append(uid, message, flags)
53
67
tsx . fail_outside_transaction! ( :append )
54
68
mboxrd_message = Email ::Mboxrd ::Message . new ( message )
55
69
serialized = mboxrd_message . to_serialized
56
- tsx . data [ :metadata ] << { uid : uid , length : serialized . bytesize , flags : flags }
70
+ tsx . data [ :appends ] << { uid : uid , length : serialized . bytesize , flags : flags }
57
71
mbox . append ( serialized )
58
72
end
59
73
74
+ # Stores changes to a message's metadata for later update
75
+ #
76
+ # @param uid [Integer] the UID of the message
77
+ # @param length [Integer] the length of the message
78
+ # @param flags [Array<Symbol>] the flags for the message
79
+ # @return [void]
80
+ def update ( uid , length : nil , flags : nil )
81
+ tsx . fail_outside_transaction! ( :update )
82
+ tsx . data [ :updates ] << { uid : uid , length : length , flags : flags }
83
+ end
84
+
60
85
private
61
86
62
87
attr_reader :serializer
63
88
64
89
def commit
65
90
# rubocop:disable Lint/RescueException
66
91
imap . transaction do
67
- tsx . data [ :metadata ] . each do |m |
92
+ tsx . data [ :appends ] . each do |m |
68
93
imap . append m [ :uid ] , m [ :length ] , flags : m [ :flags ]
69
94
end
95
+ tsx . data [ :updates ] . each do |m |
96
+ imap . update m [ :uid ] , length : m [ :length ] , flags : m [ :flags ]
97
+ end
70
98
rescue Exception => e
71
99
Logger . logger . error "#{ self . class } handling #{ e . class } "
72
100
imap . rollback
0 commit comments