class TestQuickMLSession

Public Instance Methods

add_member(cc) click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 191
def add_member(cc)
  sendmail('alice@example.net', 'test@example.com', 'unsubscribe', cc){'add'}
end
finish() click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 220
def finish
  #sleep 3
  #sudo kill `cat quickml.pid`
end
join_ml(from) click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 199
def join_ml(from)
  sendmail(from, 'test@example.com', 'join', 'alice@example.net'){'join'}
end
remove_member(by, member) click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 195
def remove_member(by, member)
  sendmail(by, 'test@example.com', 'remove', member){''}
end
send_japanese_large_mail() click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 213
def send_japanese_large_mail
  message = "Content-Type: text/plain; charset=ISO-2022-JP\n\n"
  message += "oooooooooo\n" * 500000
  sendmail('alice@example.net', 'test@example.com',
           "=?iso-2022-jp?B?GyRCJEckKyQkGyhC?="){message}
end
send_japanese_mail(from) click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 181
    def send_japanese_mail(from)
      message = <<'EOF'
Content-Type: text/plain; charset=ISO-2022-JP

日本語ですよ
EOF
      sendmail(from, 'test@example.com',
               "=?iso-2022-jp?B?GyRCJEYkOSRIGyhC?="){message}
    end
send_japanese_multipart_mail(from) click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 128
    def send_japanese_multipart_mail(from)
      message = <<'EOF'
Mime-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: Multipart/Mixed;
 boundary="--Next_Part(Wed_Oct_16_19:21:12_2002_747)--"

----Next_Part(Wed_Oct_16_19:21:12_2002_747)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

てすと
----Next_Part(Wed_Oct_16_19:21:12_2002_747)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename='foobar.txt'

foobar

----Next_Part(Wed_Oct_16_19:21:12_2002_747)----
EOF
      sendmail(from, 'test@example.com',
               "=?iso-2022-jp?B?GyRCJF4kayRBJFEhPCRIGyhC?="){message}
    end
send_large_mail() click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 203
def send_large_mail
  message = "oooooooooo\n" * 500000
  sendmail('alice@example.net', 'test@example.com', 'large'){message}
end
send_longline_mail() click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 208
def send_longline_mail
  message = 'o' * 2000 + "\n"
  sendmail('alice@example.net', 'test@example.com', 'longline'){message}
end
send_multipart_mail(from) click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 153
    def send_multipart_mail(from)
      message = <<'EOF'
Mime-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: Multipart/Mixed;
 boundary="--Next_Part(Wed_Oct_16_19:21:12_2002_747)--"

----Next_Part(Wed_Oct_16_19:21:12_2002_747)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

test
----Next_Part(Wed_Oct_16_19:21:12_2002_747)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename='foobar.txt'

foobar

----Next_Part(Wed_Oct_16_19:21:12_2002_747)----
EOF
      sendmail(from, 'test@example.com', 'multipart'){message}
    end
send_normal_mail(from) click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 124
def send_normal_mail(from)
  sendmail(from, 'test@example.com', 'test'){'test'}
end
sendmail(from, to, subject, cc='') { || ... } click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 110
def sendmail(from, to, subject, cc='')
  message = yield
  contents = []
  contents << "To: #{to}\n"
  contents << "From: #{from}\n"
  contents << "Subject: #{subject}\n"
  contents << "Cc: #{cc}\n"
  contents << "\n" if /\n\z/ !~ message
  contents << message
  Net::SMTP.start('localhost') {|smtp|
    smtp.send_mail(contents, from, to)
  }
end
setup_config() click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 67
    def setup_config
      {
        # QuickML Internal use.
      # :message_catalog = nil  # for English messages
        :message_catalog => Dir.pwd+'/../messages.ja',

        # For test and debug.
        :verbose_mode  => true,

        # Server setting.
        :user          => 'quickml',
        :group         => 'quickml',
#       :ml_port      => 10025,
        :ml_port       => 9196,

        # Send mail setting.
        :smtp_host     => 'localhost',

        # Mailing list setting.
        :domain                => Socket.gethostname,
        :postmaster    => 'info@localhost',
        :info_url      => 'http://localhost/',

        # Mailing list server setting.
        :sweep_interval        => 10,
        :allowable_error_interval      => 3,
        :max_threads   => 10,
        :timeout       => 120,

        # Config for each group.
        :auto_unsubscribe_count                => 3,
        :max_mail_length=> 1024 * 1024,
        :max_members   => 2,
        :ml_alert_time => 160,
        :ml_life_time  => 170,

        # Setting for directories and files.
        :sites_dir     => Dir.pwd+'/mldata',
        :log_dir       => '.',
        :ml_pid_file   => Dir.pwd+'/quickml.pid',
      }
    end
start() click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 59
def start
  #cat /dev/null > /var/spool/mail/$USER
  #sudo rm -rf mldata
  #rm -f quickml.log
  #mkdir mldata
  #sudo ruby -I ../lib ../quickml quickmlrc.test
end
test_quickml_main() click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 21
def test_quickml_main
  start
  send_normal_mail 'bob@example.net' # create a new ML by bob@example.net
  send_normal_mail 'alice@example.net'      # must be rejected
  send_japanese_multipart_mail 'alice@example.net'  # must be rejected
  send_multipart_mail 'alice@example.net'   # must be rejected
  unsubscribe 'bob@example.net'             # close ML

  send_normal_mail 'alice@example.net'      # create new ML
  send_normal_mail 'ALICE@EXAMPLE.NET'      # case-insensitive OK?
  send_multipart_mail 'alice@example.net'
  send_japanese_mail 'alice@example.net'    # Japanese
  send_normal_mail 'bob@example.net'                # must be rejected
  add_member 'charlie@example.net'
  add_member 'bob@example.net'              # exceeds :max_members
  remove_member 'ALICE@EXAMPLE.NET', 'charlie@example.net'
  join_ml 'bob@example.net'
  remove_member 'bob@example.net', 'Alice@Example.Net'
  send_normal_mail 'alice@example.net'      # return
  remove_member 'alice@example.net', 'bob@example.net'
  add_member 'nonexistent'
  send_normal_mail 'alice@example.net'
  send_normal_mail 'Alice@Example.Net'
  send_normal_mail 'ALICE@EXAMPLE.NET'      # exceeds :auto_unsubscribe_count
  unsubscribe 'alice@example.net'           # close ML

  send_normal_mail 'alice@example.net'      #
  unsubscribe 'alice@example.net'           # close ML (English report mail)

  send_normal_mail 'alice@example.net' # re-create new ML by alice@example.net
  send_large_mail
  send_longline_mail
  send_japanese_multipart_mail 'alice@example.net'
  send_japanese_large_mail
  sleep 180                                 # automatic ML deletion
  finish
end
unsubscribe(from) click to toggle source
# File vendor/qwik/lib/qwik/test-ml-info.rb, line 177
def unsubscribe(from)
  sendmail(from, 'test@example.com', 'unsubscribe'){''}
end