Yes, i know this type of things are written many times. But my approach to it is for the IMAP protocol later. This is the 1st step to start from.
So you are looking for a package which extract your files from zip, tar, tar.gz, gz etc. Zip can be done easily with some PHP functions but for tar and other Linux archives we need some library to work with and extract files.
To make IMAP working with PHP we need to install these modules, install these from synaptic package manager.