Ruby Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Ruby
Examples

Quick Start
Ruby Unicode
Ruby Byte Array
Ruby Certs
Ruby Email
Ruby Encryption
Ruby FTP
HTML-to-XML
Ruby HTTP
Ruby IMAP
Ruby MHT
Ruby MIME
Ruby S/MIME
Ruby Signatures
Ruby RSA
Ruby Socket
Ruby Spider
Ruby Tar
Ruby Upload
Ruby XML
Ruby XMP
Ruby Zip

More Examples...
String
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
LZW
Bz2
Icon

 

 

 

 

 

 

 

Read S/MIME Encrypted Email

Read S/MIME encrypted email.

Download Chilkat Ruby Library

require 'chilkat'

imap = Chilkat::CkImap.new()

#  Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial")
if (success != true)
    print imap.lastErrorText() + "\n"
    exit
end

#  Connect to an IMAP server.
success = imap.Connect("mail.chilkatsoft.com")
if (success != true)
    print imap.lastErrorText() + "\n"
    exit
end

#  Login
success = imap.Login("myLogin","myPassword")
if (success != true)
    print imap.lastErrorText() + "\n"
    exit
end

#  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox")
if (success != true)
    print imap.lastErrorText() + "\n"
    exit
end

#  The AutoUnwrapSecurity method controls whether signed/encrypted emails are automatically
#  decrypted and/or verified.

#  When set to true, which is the default, security envelopes are automatically "unwrapped"
#  when a message is retrieved from the server. Signed emails are automatically verified, and
#  encrypted emails are automatically decrypted, restoring the email to the original state before
#  signing and/or encrypting. Information about the signing and encrypting certificates can be
#  retrieved from the Email object (methods: GetSignedByCert, GetEncryptedByCert;
#  properties: SignedBy, EncryptedBy, SignaturesValid, Decrypted, ReceivedSigned,
#  ReceivedEncrypted).

#  This example will explicity set AutoUnwrapSecurity to true, even though it's
#  already the default value:
imap.put_AutoUnwrapSecurity(true)

#  The NumMessages property contains the number of messages in the selected mailbox.
numToFetch = imap.get_NumMessages()
#  Download all the email in the Inbox.

bundle = imap.FetchSequence(1,numToFetch)
if (bundle == nil )
    print imap.lastErrorText() + "\n"
    exit
end

#  Loop over the bundle,

for i in 0 .. bundle.get_MessageCount() - 1

    email = bundle.GetEmail(i)

    print email.ck_from() + "\n";
    print email.subject() + "\n";

    #  At this point, if the email was signed and/or encrypted, it is already "unwrapped", i.e.
    #  the email is already decrypted and in a state as if it were never signed or encrypted.
    #  You may check to see if the email was received encrypted or signed, and if so,
    #  whether it was successfully unwrapped and who signed or encrypted it:
    if (email.get_ReceivedEncrypted() == true)

        print "This email was encrypted when received." + "\n";
        if (email.get_Decrypted() == true)
            print "This email was successfully decrypted.  It was encrypted by:" + "\n";
            print email.encryptedBy() + "\n";
        else
            print "This email was not decrypted." + "\n";
        end

    end

    if (email.get_ReceivedSigned() == true)

        print "This email was signed when received." + "\n";
        if (email.get_SignaturesValid() == true)
            print "The signature was verified.  It was signed by:" + "\n";
            print email.signedBy() + "\n";
        else
            print "The signature verification failed." + "\n";
        end

    end

    #  The email's body, HTML body, attachments, etc.
    #  are decrypted and available just like any non-encrypted email.

    print "--" + "\n";

end

#  Disconnect from the IMAP server.
imap.Disconnect()


 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.