Class: CleanMail

Inherits:
LacunaUtil::Task show all
Defined in:
lib/lacuna_util/task/clean_mail.rb

Instance Method Summary collapse

Methods inherited from LacunaUtil::Task

#initialize

Constructor Details

This class inherits a constructor from LacunaUtil::Task

Instance Method Details

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lacuna_util/task/clean_mail.rb', line 6

def run
    super

    status = Lacuna::Empire.get_status

    if status['empire']['has_new_messages'].to_i == 0
        puts "No messages to delete! You're all clear!"
        return
    end

    # Array of message ids representing messages needing to be trashed.
    to_trash = []

    page = 1
    seen = 0
    tags = ['Parliament', 'Probe']

    # Isolationists are not affected by Fissures.
    tags << 'Fissure' if status['empire']['is_isolationist'].to_i > 0

    while true
        puts "Checking page #{page}"

        inbox = Lacuna::Inbox.view_inbox({
            :tags => tags,
            :page_number => page,
        })

        inbox['messages'].each do |message|
            seen += 1
            to_trash << message['id']
        end

        # Check if this is the last page.
        if inbox['message_count'].to_i == seen
            break
        else
            page += 1
        end
    end

    puts "Trashing #{to_trash.size} messages... hang on tight, kid!"
    Lacuna::Inbox.trash_messages to_trash
end