Ignore:
Timestamp:
04/05/19 10:25:31 (5 years ago)
Author:
bln4
Message:

When loading in messages from the mail databases now uses the timestamp last-accessed companion file to only load in new ones.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/auth/Mail.java

    r1277 r1283  
    22
    33import java.io.File;
     4import java.io.FileNotFoundException;
    45import java.io.IOException;
    56import java.nio.file.Path;
     
    1718import java.sql.SQLException;
    1819import java.sql.Statement;
     20import java.text.ParseException;
     21import java.text.SimpleDateFormat;
    1922import java.util.ArrayList;
    2023import java.util.Arrays;
    2124import java.util.Base64;
     25import java.util.Date;
    2226import java.util.HashMap;
    2327import java.util.List;
    2428import java.util.Map;
     29import java.util.Scanner;
    2530
    2631import javax.crypto.BadPaddingException;
     
    7883                PublicKey publicKey = null;
    7984                try {
    80                         publicKey = Authenticator.getInstance().getPublicKey(colleagueName);
     85                        publicKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueName);
    8186                } catch (InvalidKeySpecException | NoSuchAlgorithmException | KeyStoreException | CertificateException
    8287                                | ClassNotFoundException | IOException | SQLException e) {
     
    182187                                }
    183188                               
    184                                 //String arguments = new String(c.doFinal(Base64.getDecoder().decode(mail.args)));
    185                                 filtered.add(new MailEntry(mail.timestamp, sender, receiverDecrypted, message, message2, options));
     189                                Path lastAccessedFile = Paths.get(FrameIO.DEAD_DROPS_PATH).resolve(sender).resolve(name + ".last-accessed");
     190                                SimpleDateFormat format = new SimpleDateFormat("ddMMMyyyy[HH:mm]");
     191                                MailEntry mailEntry = new MailEntry(mail.timestamp, sender, receiverDecrypted, message, message2, options);
     192                                try (Scanner in = new Scanner(lastAccessedFile.toFile())) {
     193                                        Date lastAccessedTimestamp = format.parse(in.nextLine());
     194                                        Date mailTimestamp = format.parse(mail.timestamp);
     195                                        if (mailTimestamp.after(lastAccessedTimestamp)) {
     196                                                filtered.add(mailEntry);
     197                                        }
     198                                } catch (FileNotFoundException e) {
     199                                        // It may not have been created yet, then err on the safe side and add it in.
     200                                        filtered.add(mailEntry);
     201                                } catch (ParseException e) {
     202                                        // If we fail to parse, then err on the safe side and add it in.
     203                                        filtered.add(mailEntry);
     204                                }                       
     205                               
    186206                        }
    187207                }
Note: See TracChangeset for help on using the changeset viewer.