Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
(Chilkat for Android™ API) Read IMAP Email HeadersCall FetchHeaders to download only the email headers. Download: Chilkat for Android™ Java Libraries // Important: Don't forget to include the call to System.loadLibrary // as shown at the bottom of this code sample. package com.test; import android.app.Activity; import com.chilkatsoft.*; import android.widget.TextView; import android.os.Bundle; public class SimpleActivity extends Activity { // Called when the activity is first created. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); String outStr = ""; CkImap imap = new CkImap(); boolean success; // Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial"); if (success != true) { outStr += imap.lastErrorText() + "\n"; tv.setText(outStr); setContentView(tv); return; } // Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com"); if (success != true) { outStr += imap.lastErrorText() + "\n"; tv.setText(outStr); setContentView(tv); return; } // Login success = imap.Login("****","****"); if (success != true) { outStr += imap.lastErrorText() + "\n"; tv.setText(outStr); setContentView(tv); return; } // Select an IMAP mailbox success = imap.SelectMailbox("Inbox"); if (success != true) { outStr += imap.lastErrorText() + "\n"; tv.setText(outStr); setContentView(tv); return; } CkMessageSet messageSet; // We can choose to fetch UIDs or sequence numbers. boolean fetchUids; fetchUids = true; // Get the message IDs of all the emails in the mailbox messageSet = imap.Search("ALL",fetchUids); if (messageSet == null ) { outStr += imap.lastErrorText() + "\n"; tv.setText(outStr); setContentView(tv); return; } // When downloading headers, each email object contains // (obviously) the headers, but the body will be missing. // Also, attachments will not be included. However, it is // possible to get information about the attachments // as well as the complete size of the email. CkEmailBundle bundle; bundle = imap.FetchHeaders(messageSet); if (bundle == null ) { outStr += imap.lastErrorText() + "\n"; tv.setText(outStr); setContentView(tv); return; } // Loop over the email objects and display information // about each: int i; for (i = 0; i <= bundle.get_MessageCount() - 1; i++) { CkEmail email; email = bundle.GetEmail(i); // Display the From and Subject outStr += email.ck_from() + "\n"; outStr += email.subject() + "\n"; // Display the recipients: int j; String name; String addr; for (j = 0; j <= email.get_NumTo() - 1; j++) { name = email.getToName(j); addr = email.getToAddr(j); outStr += name + ", " + addr + "\n"; } for (j = 0; j <= email.get_NumCC() - 1; j++) { name = email.getCcName(j); addr = email.getCcAddr(j); outStr += name + ", " + addr + "\n"; } // Show the total size of the email, including body and attachments: outStr += email.get_Size() + "\n"; // When a full email is downloaded, we would use the // email.NumAttachments property in conjunction with the // email.GetMailAttach* methods. // However, when an email object contains only the header, // we need to access the attachment info differently: int numAttach; numAttach = imap.GetMailNumAttach(email); for (j = 0; j <= numAttach - 1; j++) { outStr += imap.getMailAttachFilename(email,j) + "\n"; int attachSize; attachSize = imap.GetMailAttachSize(email,j); outStr += " size = " + attachSize + " bytes" + "\n"; } outStr += "--" + "\n"; } // Disconnect from the IMAP server. imap.Disconnect(); tv.setText(outStr); setContentView(tv); } static { // Important: Make sure the name passed to loadLibrary matches the shared library // found in your project's libs/armeabi directory. // for "libchilkat.so", pass "chilkat" to loadLibrary // for "libchilkatemail.so", pass "chilkatemail" to loadLibrary // etc. // System.loadLibrary("chilkat"); // Note: If the incorrect library name is passed to System.loadLibrary, // then you will see the following error message at application startup: //"The application <your-application-name> has stopped unexpectedly. Please try again." } } |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.