fixing attachment delete
authorVolker Birk <vb@pep.foundation>
Wed, 26 Oct 2016 05:14:14 +0200
changeset 1338515f4edb52d0
parent 1337 c5ebf188d01f
child 1339 a8b118fae4ae
fixing attachment delete
src/sync_impl.c
     1.1 --- a/src/sync_impl.c	Tue Oct 25 08:45:20 2016 +0200
     1.2 +++ b/src/sync_impl.c	Wed Oct 26 05:14:14 2016 +0200
     1.3 @@ -261,8 +261,7 @@
     1.4      bool expired = false;
     1.5      bool discarded = false;
     1.6      bool force_keep_msg = false;
     1.7 -    
     1.8 -    bloblist_t *last = NULL;
     1.9 +
    1.10      for (bloblist_t *bl = src->attachments; bl && bl->value; bl = bl->next) {
    1.11          if (bl->mime_type && strcasecmp(bl->mime_type, "application/pEp.sync") == 0
    1.12                  && bl->size) {
    1.13 @@ -405,25 +404,7 @@
    1.14  
    1.15                  if (status != PEP_STATUS_OK)
    1.16                      return status;
    1.17 -
    1.18              }
    1.19 -
    1.20 -            if (!session->keep_sync_msg) {
    1.21 -                bloblist_t *blob = bl;
    1.22 -                if (last)
    1.23 -                    last->next = bl->next;
    1.24 -                else
    1.25 -                    src->attachments = bl->next;
    1.26 -
    1.27 -                blob->next = NULL;
    1.28 -                free_bloblist(blob);
    1.29 -            }
    1.30 -            else {
    1.31 -                last = bl;
    1.32 -            }
    1.33 -        }
    1.34 -        else {
    1.35 -            last = bl;
    1.36          }
    1.37      }
    1.38  
    1.39 @@ -444,9 +425,31 @@
    1.40          return PEP_MESSAGE_DISCARDED;
    1.41      }
    1.42  
    1.43 -    if(discarded)
    1.44 +    if (discarded)
    1.45          return PEP_MESSAGE_DISCARDED;
    1.46  
    1.47 +    if (!session->keep_sync_msg) {
    1.48 +        bloblist_t *last = NULL;
    1.49 +        for (bloblist_t *bl = src->attachments; bl && bl->value; ) {
    1.50 +            if (bl->mime_type && strcasecmp(bl->mime_type, "application/pEp.sync") == 0) {
    1.51 +                bloblist_t *b = bl;
    1.52 +                bl = bl->next;
    1.53 +                if (!last)
    1.54 +                    src->attachments = bl;
    1.55 +                else
    1.56 +                    last->next = bl;
    1.57 +                free(b->mime_type);
    1.58 +                free(b->filename);
    1.59 +                free(b->value);
    1.60 +                free(b);
    1.61 +            }
    1.62 +            else {
    1.63 +                last = bl;
    1.64 +                bl = bl->next;
    1.65 +            }
    1.66 +        }
    1.67 +    }
    1.68 +
    1.69      return PEP_STATUS_OK;
    1.70  }
    1.71