Module: MailGrabber::DatabaseQueries

Included in:
DatabaseHelper
Defined in:
lib/mail_grabber/database_queries.rb

Instance Method Summary collapse

Instance Method Details

#create_mail_part_table(db) ⇒ Object

Create a mail part table if it does not exist.

Parameters:

  • db (SQLite3::Database)

    to execute the create table query



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mail_grabber/database_queries.rb', line 26

def create_mail_part_table(db)
  db.execute("    CREATE TABLE IF NOT EXISTS mail_part (\n      id INTEGER PRIMARY KEY,\n      mail_id INTEGER NOT NULL,\n      cid TEXT,\n      mime_type TEXT,\n      is_attachment INTEGER,\n      is_inline INTEGER,\n      filename TEXT,\n      charset TEXT,\n      body BLOB,\n      size INTEGER,\n      created_at DATETIME DEFAULT CURRENT_DATETIME,\n      FOREIGN KEY (mail_id) REFERENCES mail(id) ON DELETE CASCADE\n    )\n  SQL\nend\n")

#create_mail_table(db) ⇒ Object

Create a mail table if it does not exist.

Parameters:

  • db (SQLite3::Database)

    to execute the create table query



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mail_grabber/database_queries.rb', line 8

def create_mail_table(db)
  db.execute("    CREATE TABLE IF NOT EXISTS mail (\n      id INTEGER PRIMARY KEY,\n      subject TEXT,\n      senders TEXT,\n      recipients TEXT,\n      carbon_copy TEXT,\n      blind_carbon_copy TEXT,\n      raw BLOB,\n      created_at DATETIME DEFAULT CURRENT_DATETIME\n    )\n  SQL\nend\n")

#insert_into_mail_part_querySrting

Insert mail part query.

Returns:

  • (Srting)

    with the insert mail part query



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mail_grabber/database_queries.rb', line 66

def insert_into_mail_part_query
  "    INSERT INTO mail_part (\n      mail_id,\n      cid,\n      mime_type,\n      is_attachment,\n      is_inline,\n      filename,\n      charset,\n      body,\n      size,\n      created_at\n    )\n    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))\n  SQL\nend\n"

#insert_into_mail_querySrting

Insert mail query.

Returns:

  • (Srting)

    with the insert mail query



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mail_grabber/database_queries.rb', line 48

def insert_into_mail_query
  "    INSERT INTO mail (\n      subject,\n      senders,\n      recipients,\n      carbon_copy,\n      blind_carbon_copy,\n      raw,\n      created_at\n    )\n    VALUES (?, ?, ?, ?, ?, ?, datetime('now'))\n  SQL\nend\n"

#select_messages_with_pagination_querySrting

Select messages with a pagination query.

Returns:

  • (Srting)

    with the select messages query



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/mail_grabber/database_queries.rb', line 87

def select_messages_with_pagination_query
  "    SELECT id, subject, senders, created_at\n    FROM mail\n    WHERE id NOT IN (\n      SELECT id\n      FROM mail\n      ORDER BY id DESC, created_at DESC\n      LIMIT ?\n    )\n    ORDER BY id DESC, created_at DESC\n    LIMIT ?\n  SQL\nend\n"