EXPORTED unsigned mailbox_should_archive(struct mailbox *mailbox,
                                         const struct index_record *record,
                                         void *rock)
{
    int archive_after = config_getduration(IMAPOPT_ARCHIVE_AFTER, 'd');
    time_t cutoff = time(0) - archive_after;
    if (rock) cutoff = *((time_t *)rock);

    int64_t archive_size = config_getbytesize(IMAPOPT_ARCHIVE_MAXSIZE, 'K');
    if (archive_size < 0) archive_size = 0;
    size_t maxsize = archive_size;

    int keepflagged = config_getswitch(IMAPOPT_ARCHIVE_KEEPFLAGGED);

    /* never pull messages back from the archives */
    if (record->internal_flags & FLAG_INTERNAL_ARCHIVED)
        return 1;

    /* first check if we're archiving anything */
    if (!config_getswitch(IMAPOPT_ARCHIVE_ENABLED))
        return 0;

    /* always archive big messages */
    if (record->size >= maxsize)
        return 1;

    /* archive everything in DELETED mailboxes */
    if (mboxname_isdeletedmailbox(mailbox_name(mailbox), NULL))
        return 1;

    /* Calendar and Addressbook are small files and need to be hot */
    switch (mbtype_isa(mailbox_mbtype(mailbox))) {
    case MBTYPE_ADDRESSBOOK:
        return 0;
    case MBTYPE_CALENDAR:
        return 0;
    }

    /* don't archive flagged messages */
    if (keepflagged && (record->system_flags & FLAG_FLAGGED))
        return 0;

    /* archive all other old messages */
    if (record->internaldate <= cutoff)
        return 1;

    /* and don't archive anything else! */
    return 0;
}
EXPORTED unsigned mailbox_should_archive(struct mailbox *mailbox,
                                         const struct index_record *record,
                                         void *rock)
{
    int archive_after = config_getduration(IMAPOPT_ARCHIVE_AFTER, 'd');
    time_t cutoff = time(0) - archive_after;
    if (rock) cutoff = *((time_t *)rock);

    int64_t archive_size = config_getbytesize(IMAPOPT_ARCHIVE_MAXSIZE, 'K');
    if (archive_size < 0) archive_size = 0;
    size_t maxsize = archive_size;

    int keepflagged = config_getswitch(IMAPOPT_ARCHIVE_KEEPFLAGGED);

     
    if (record->internal_flags & FLAG_INTERNAL_ARCHIVED)
        return 1;

     
    if (!config_getswitch(IMAPOPT_ARCHIVE_ENABLED))
        return 0;

     
    if (record->size >= maxsize)
        return 1;

     
    if (mboxname_isdeletedmailbox(mailbox_name(mailbox), NULL))
        return 1;

     
    switch (mbtype_isa(mailbox_mbtype(mailbox))) {
    case MBTYPE_ADDRESSBOOK:
        return 0;
    case MBTYPE_CALENDAR:
        return 0;
    }

     
    if (keepflagged && (record->system_flags & FLAG_FLAGGED))
        return 0;

     
    if (record->internaldate <= cutoff)
        return 1;

     
    return 0;
}