Class: Sakura::MailAddress
- Inherits:
-
Object
- Object
- Sakura::MailAddress
- Defined in:
- lib/sakura/mail_address.rb
Constant Summary collapse
- MAIL_URL =
BASE_URL + 'rs/mail'
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#link_to_delete ⇒ Object
readonly
Returns the value of attribute link_to_delete.
-
#quota ⇒ Object
Returns the value of attribute quota.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
-
#virus_scan ⇒ Object
Returns the value of attribute virus_scan.
Class Method Summary collapse
- .all ⇒ Object
- .create(local_part, password) ⇒ Object
- .find(local_part) ⇒ Object
- .header ⇒ Object
- .new_from_element(element) ⇒ Object
- .tabularize(*args) ⇒ Object
Instance Method Summary collapse
- #delete ⇒ Object
- #delete_forward_to(mail) ⇒ Object
- #detail ⇒ Object
- #disable_keep ⇒ Object
- #disable_virus_scan ⇒ Object
- #enable_keep ⇒ Object
- #enable_virus_scan ⇒ Object
- #forward_list(page = nil) ⇒ Object
- #forward_to(mail) ⇒ Object
-
#initialize(address, virus_scan, usage, quota, link, link_to_delete = nil) ⇒ MailAddress
constructor
A new instance of MailAddress.
- #keep(page = nil) ⇒ Object
- #keep=(value) ⇒ Object
- #password=(value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(address, virus_scan, usage, quota, link, link_to_delete = nil) ⇒ MailAddress
Returns a new instance of MailAddress.
56 57 58 59 60 61 62 63 |
# File 'lib/sakura/mail_address.rb', line 56 def initialize(address, virus_scan, usage, quota, link, link_to_delete=nil) @address = address @virus_scan = virus_scan == '○' @usage = usage @quota = quota @link = link @link_to_delete = link_to_delete end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
7 8 9 |
# File 'lib/sakura/mail_address.rb', line 7 def address @address end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
7 8 9 |
# File 'lib/sakura/mail_address.rb', line 7 def link @link end |
#link_to_delete ⇒ Object (readonly)
Returns the value of attribute link_to_delete.
7 8 9 |
# File 'lib/sakura/mail_address.rb', line 7 def link_to_delete @link_to_delete end |
#quota ⇒ Object
Returns the value of attribute quota.
7 8 9 |
# File 'lib/sakura/mail_address.rb', line 7 def quota @quota end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
7 8 9 |
# File 'lib/sakura/mail_address.rb', line 7 def usage @usage end |
#virus_scan ⇒ Object
Returns the value of attribute virus_scan.
7 8 9 |
# File 'lib/sakura/mail_address.rb', line 7 def virus_scan @virus_scan end |
Class Method Details
.all ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/sakura/mail_address.rb', line 21 def all page = Client.current_session.get(MAIL_URL) page.all(:xpath, '//a[contains(@href, "mail?Username=")]/../..').map{|element| MailAddress.new_from_element(element) } end |
.create(local_part, password) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sakura/mail_address.rb', line 10 def create(local_part, password) Client.current_session.process(MAIL_URL) do fill_in 'NewUsername', with: local_part fill_in 'Password1', with: password fill_in 'Password2', with: password find('input[name="Submit_useradd"]').click end true end |
.find(local_part) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/sakura/mail_address.rb', line 29 def find(local_part) page = Client.current_session.get(MAIL_URL) element = page.find(:xpath, "//a[@href=\"mail?Username=#{local_part}\"]/../..") MailAddress.new_from_element(element) end |
.header ⇒ Object
41 42 43 44 |
# File 'lib/sakura/mail_address.rb', line 41 def header str = tabularize('address', 'virus_scan', 'usage', 'quota', '%') "#{str}\n#{'-' * (str.size+1)}" end |
.new_from_element(element) ⇒ Object
36 37 38 39 |
# File 'lib/sakura/mail_address.rb', line 36 def new_from_element(element) arguments = element.all('td').map(&:text)[0..-2] + element.all('a').map{|i| i[:href] } MailAddress.new(*arguments) end |
.tabularize(*args) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/sakura/mail_address.rb', line 46 def tabularize(*args) args[0].ljust(20) << args[1].to_s.rjust(11) << "#{args[2]} /".to_s.rjust(15) << args[3].to_s.rjust(10) << " (#{args[4].to_s.rjust(3)})" end |
Instance Method Details
#delete ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/sakura/mail_address.rb', line 65 def delete link = @link_to_delete Client.current_session.process(MAIL_URL) do find("a[href=\"#{link}\"]").click end true end |
#delete_forward_to(mail) ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/sakura/mail_address.rb', line 158 def delete_forward_to(mail) Client.current_session.process(MAIL_URL + @link) do find_field('DeleteAddress[]').select(mail) find('a[href="javascript:tr_delete();"]').click end @forward_list ||= [] @forward_list.delete mail end |
#detail ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/sakura/mail_address.rb', line 172 def detail page = Client.current_session.get(MAIL_URL + @link) "usage / quota: \#{usage} / \#{quota} (\#{percentage(@usage, @quota)})\nforward_to: \#{forward_list(page).join(' ')}\nkeep mail?: \#{keep(page)}\nvirus_scan?: \#{virus_scan}\n EOS\nend\n" |
#disable_keep ⇒ Object
131 132 133 |
# File 'lib/sakura/mail_address.rb', line 131 def disable_keep keep = false end |
#disable_virus_scan ⇒ Object
105 106 107 |
# File 'lib/sakura/mail_address.rb', line 105 def disable_virus_scan virus_scan = false end |
#enable_keep ⇒ Object
127 128 129 |
# File 'lib/sakura/mail_address.rb', line 127 def enable_keep keep = true end |
#enable_virus_scan ⇒ Object
101 102 103 |
# File 'lib/sakura/mail_address.rb', line 101 def enable_virus_scan virus_scan = true end |
#forward_list(page = nil) ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/sakura/mail_address.rb', line 135 def forward_list(page=nil) if @forward_list.nil? page ||= Client.current_session.get(MAIL_URL + @link) @forward_list = page.all('select[name="DeleteAddress[]"] option').map(&:text) end @forward_list end |
#forward_to(mail) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/sakura/mail_address.rb', line 144 def forward_to(mail) Client.current_session.process(MAIL_URL + @link) do execute_script " var f = document.Transfer;\n f.Address.value = '\#{mail}';\n f.SubAction.value = 'add';\n f.submit();\n JS\n end\n\n @forward_list ||= []\n @forward_list << mail\nend\n" |
#keep(page = nil) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/sakura/mail_address.rb', line 109 def keep(page=nil) if @keep.nil? page ||= Client.current_session.get(MAIL_URL + @link) @keep = page.find('input[name="Save"]:checked').value == '1' end @keep end |
#keep=(value) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/sakura/mail_address.rb', line 118 def keep=(value) value = value ? 1 : 0 Client.current_session.process(MAIL_URL + @link) do find("input[name='Save'][value='#{value}']").click end @keep = value == 1 end |
#password=(value) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/sakura/mail_address.rb', line 84 def password=(value) Client.current_session.process(MAIL_URL + @link) do fill_in 'Password1', with: value fill_in 'Password2', with: value find('input[name="Submit_password"]').click end end |
#to_s ⇒ Object
168 169 170 |
# File 'lib/sakura/mail_address.rb', line 168 def to_s self.class.tabularize(@address, @virus_scan, @usage, @quota, percentage(@usage, @quota)) end |