123456789_123456789_123456789_123456789_123456789_

Class: Net::IMAP::CopyUIDData

Relationships & Source Files
Inherits: Object
Defined in: lib/net/imap/uidplus_data.rb

Overview

NOTE: CopyUIDData will replace UIDPlusData for COPYUID in the 0.6.0 release. To use CopyUIDData before 0.6.0, set Config#parser_use_deprecated_uidplus_data to false.

CopyUIDData represents the ResponseCode#data that accompanies the COPYUID response code.

A server that supports UIDPLUS (or IMAP4rev2) should send CopyUIDData in response to copy, uid_copy, move, and uid_move commands—unless the destination mailbox reports UIDNOTSTICKY.

Note that copy and uid_copy return CopyUIDData in their TaggedResponse. But move and uid_move should send CopyUIDData in an UntaggedResponse response before sending their TaggedResponse. However some servers do send CopyUIDData in the TaggedResponse for MOVE commands—this complies with the older UIDPLUS specification but is discouraged by the MOVE extension and disallowed by IMAP4rev2.

Required capability

Requires either UIDPLUS [RFC4315] or IMAP4rev2 capability.

Class Method Summary

Instance Method Summary

Constructor Details

.new(uidvalidity:, source_uids:, assigned_uids:) ⇒ CopyUIDData

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 138

def initialize(uidvalidity:, source_uids:, assigned_uids:)
  uidvalidity   = Integer(uidvalidity)
  source_uids   = SequenceSet[source_uids]
  assigned_uids = SequenceSet[assigned_uids]
  NumValidator.ensure_nz_number(uidvalidity)
  if source_uids.include_star? || assigned_uids.include_star?
    raise DataFormatError, "uid-set cannot contain '*'"
  elsif source_uids.count_with_duplicates != assigned_uids.count_with_duplicates
    raise DataFormatError, "mismatched uid-set sizes for %s and %s" % [
      source_uids, assigned_uids
    ]
  end
  super
end

Instance Method Details

#[](source_uid)

Alias for #assigned_uid_for.

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 190

alias :[] :assigned_uid_for

#assigned_uid_for(source_uid) ⇒ uid #[](source_uid) ⇒ uid
Also known as: #[]

Returns the UID in the destination mailbox for the message that was copied from source_uid in the source mailbox.

This is the reverse of #source_uid_for.

Related: source_uid_for, each_uid_pair, uid_mapping

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 186

def assigned_uid_for(source_uid)
  idx = source_uids.find_ordered_index(source_uid) and
    assigned_uids.ordered_at(idx)
end

#each

Alias for #each_uid_pair.

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 225

alias each      each_uid_pair

#each_pair

Alias for #each_uid_pair.

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 224

alias each_pair each_uid_pair

#each_uid_pair Also known as: #each_pair, #each

Yields a pair of UIDs for each copied message. The first is the message’s UID in the source mailbox and the second is the UID in the destination mailbox.

Returns an enumerator when no block is given.

Please note the warning on uid_mapping before calling methods like to_h or to_a on the returned enumerator.

Related: uid_mapping, assigned_uid_for, source_uid_for

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 216

def each_uid_pair
  return enum_for(__method__) unless block_given?
  source_uids.each_ordered_number.lazy
    .zip(assigned_uids.each_ordered_number.lazy) do
      |source_uid, assigned_uid|
      yield source_uid, assigned_uid
    end
end

#size

Returns the number of messages that have been copied or moved. source_uids and the assigned_uids will both the same number of UIDs.

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 172

def size
  assigned_uids.count_with_duplicates
end

#source_uid_for(assigned_uid) ⇒ uid

Returns the UID in the source mailbox for the message that was copied to assigned_uid in the source mailbox.

This is the reverse of #assigned_uid_for.

Related: assigned_uid_for, each_uid_pair, uid_mapping

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 201

def source_uid_for(assigned_uid)
  idx = assigned_uids.find_ordered_index(assigned_uid) and
    source_uids.ordered_at(idx)
end

#uid_mappingHash

Returns a hash mapping each source UID to the newly assigned destination UID.

Warning: The hash that is created may consume much more memory than the data used to create it. When handling responses from an untrusted server, check #size before calling this method.

Related: each_uid_pair, assigned_uid_for, source_uid_for

[ GitHub ]

  
# File 'lib/net/imap/uidplus_data.rb', line 237

def uid_mapping
  each_uid_pair.to_h
end