How can I save downloaded emails using Javamail in Android
<p>I build an Email application android now, so I want to save the E-Mails to the Device, Someone told eml file and serialize your own class! Can anyone will guide me in true direction please help me! And How can I load quickly all mailboxes using <code>onScrollListner()</code> method because now it very slow</p>

<p>I've using asynctask to load this! This is my code:</p>

<pre><code>private class CheckMailInboxTask extends AsyncTask&lt;Integer, Void, Message[]&gt;{
    private int count;
    private ProgressDialog progressDialog;
    private Message[] messages;
    private boolean statusMail = true;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("Loading mail");
        progressDialog.setMessage("Please wait...");
        progressDialog.show();
    }
    @Override
    protected Message[] doInBackground(Integer... params) {
        try {
            messages = AccueilActivity.emailManager.getMails();
            EmailManager.inbox.addMessageCountListener(new MessageCountAdapter() {
                @Override
                public void messagesAdded(MessageCountEvent e) {
                    super.messagesAdded(e);
                    System.out.println("New Message");
                    try {
                        Message[] messages = e.getMessages();
                        int count = messages.length;
                        for(int i=(count - 1);i &gt;= 0;i--){
                            final MimeMessage msg = (MimeMessage) messages[i];
                            Mail email = null;
                            try {
                                email = new Mail(msg);
                                email.set_box(true);
                                Mail.INBOX.add(0,email);
                                Mail.LISTBOOL.add(Boolean.valueOf(true));//Nampiako
                                if(BoiteReceptionActivity.handler != null){
                                    BoiteReceptionActivity.handler.sendEmptyMessage(1);
                                    ab.setSubtitle("1 mail non lu(s)");
                                }
                            } catch (IOException ex) {
                                ex.printStackTrace();
                            }
                        }
                    } catch (MessagingException emx) {
                    }
                }
            });
            new Thread(new Runnable() {

                @Override
                public void run() {
                    System.out.println("UUUUUUUUUUUUUUUUUUUUU");
                    if (EmailManager.inbox instanceof IMAPFolder) {
                        final IMAPFolder imapFolder = (IMAPFolder)EmailManager.inbox;
                        startListening(imapFolder);
                    }
                    System.out.println("DDDDDDDDDDDDDDDDDDDDD");
                }
            }).start();

            count = messages.length;
            for(int i=(count - 1);i &gt;= 0;i--){
                MimeMessage msg = (MimeMessage) messages[i];
                Mail email = null;
                try {
                    if(msg.isSet(Flags.Flag.SEEN)){
                        email = new Mail(msg);
                        email.set_box(true);
                        Mail.INBOX.add(email);
                        Mail.LISTBOOL.add(Boolean.valueOf(false));
                        Log.d("SIZE OF MAIL_INBOX SEEN", ""+Mail.INBOX.size());
                        Log.d("SIZE OF BOOL SEEN", ""+Mail.LISTBOOL.get(0));

                    }else {
                        email = new Mail(msg);
                        email.set_box(true);
                        Mail.INBOX.add(email);
                        Mail.LISTBOOL.add(Boolean.valueOf(true));
                        Log.d("SIZE OF MAIL_INBOX RECENT", ""+Mail.INBOX.size());
                        Log.d("SIZE OF BOOL RECENT", ""+Mail.LISTBOOL.size());

                    }
                    AccueilActivity.emailManager.setInboxList(Mail.INBOX);
                    new Thread(new Runnable() {      
                        @Override
                        public void run() {
                            BoiteReceptionActivity.this.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    //Mail.COUNT_MESSAGES = Mail.INBOX.size();
                                    Mail.in_adapteur.notifyDataSetChanged();
                                    progressDialog.dismiss();

                                }
                            });
                        }
                    }).start();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        } catch (MessagingException e) {
        }
        return messages;
    }


    @Override
    protected void onPostExecute(Message[] messages) {
        super.onPostExecute(messages);

    }
}
</code></pre>

<p><strong>EDIT</strong>
And this is my custome adapter</p>

<pre><code>public class AdapterBoiteReception extends BaseAdapter{
   private Context context;
   private List&lt;Mail&gt; listMail;
   private List&lt;Boolean&gt; listBool;

   public AdapterBoiteReception(Context ctx, List&lt;Mail&gt; list, List&lt;Boolean&gt; listBool){
      this.context = ctx;
      this.listMail = list;
      this.listBool = listBool;
  }

  @Override
  public int getCount() {
    // TODO Auto-generated method stub
     return listMail.size();
  }

  @Override
  public Object getItem(int position) {
    // TODO Auto-generated method stub
     return listMail.get(position);
 }

 @Override
 public long getItemId(int position) {
     // TODO Auto-generated method stub
     return listMail.indexOf(getItem(position));
 }

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
     View view =convertView;
        Holder mailHolder = null;
        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if(view == null){
            view = mInflater.inflate(R.layout.boite_reception_items, null);
            mailHolder = new Holder();

            mailHolder.nomTV = (TextView) view.findViewById(R.id.nomMsgTV);
            mailHolder.objetTV = (TextView) view.findViewById(R.id.objectMsgTV);
            mailHolder.dateTV = (TextView) view.findViewById(R.id.dateMsgTV);
            mailHolder.img = (ImageButton) view.findViewById(R.id.imgBtnAttache);

            view.setTag(mailHolder);
        }else
            mailHolder = (Holder) view.getTag();
        Mail mail = listMail.get(position);
        Log.d("VALUE OF LISTBOOL", ""+Boolean.valueOf(listBool.get(position)));
        if(Boolean.valueOf(listBool.get(position)).equals(Boolean.TRUE)){
            mailHolder.nomTV.setTypeface(null, Typeface.BOLD);
            mailHolder.objetTV.setTypeface(null, Typeface.BOLD);
            mailHolder.dateTV.setTypeface(null, Typeface.BOLD);

            mailHolder.nomTV.setText(mail.getNom());
            mailHolder.objetTV.setText(mail.getSubject());
            try {
                mailHolder.dateTV.setText(mail.getDate());
            } catch (MessagingException e) {
                e.printStackTrace();
            }
            if(mail.getHandlers().size() &gt; 0)
                mailHolder.img.setVisibility(View.VISIBLE);
            else
                mailHolder.img.setVisibility(View.INVISIBLE);

        }else{
            view.setBackgroundColor(Color.GRAY);
            mailHolder.nomTV.setText(mail.getNom());
            mailHolder.objetTV.setText(mail.getSubject());
            try {
                mailHolder.dateTV.setText(mail.getDate());
            } catch (MessagingException e) {
                e.printStackTrace();
            }
            if(mail.getHandlers().size() &gt; 0)
                mailHolder.img.setVisibility(View.VISIBLE);
            else
                mailHolder.img.setVisibility(View.INVISIBLE);
        }

    return view;

}
static class Holder{
    TextView nomTV;
    TextView objetTV;
    TextView dateTV;
    ImageButton img;
}
</code></pre>

<p>}</p>

<p><strong>EDIT</strong></p>

<p>@the_dani had the same of mine problem too <a href="https://stackoverflow.com/questions/35781023/saving-an-e-mail-after-downloading-with-javamail">link</a></p>