A study of the absorption systems toward the gravitationally lensed quasar APM 08279+5255 is presented. Most of the MgII systems in the redshift range 1.2-2.07, although saturated, show large residuals at the bottom of the lines. The most likely interpretation is that individual clouds within MgII halos do cover only one of the two brightest QSO images. This reveals that MgII halos are made of a collection of clouds of radius smaller than about 1 kpc. Two strong MgII absorbers at z = 1.062 and 1.181 are studied in detail. This is the first time that the NaI3303 doublet is detected in such high redshift systems. Together with the detection of the MgI2852 transition, this strongly constrains the physical characteristics of the gas. The N(NaI)/N(MgI) ratio is found to be larger than unity, implying that the gas is cool and neutral. The column densities of NaI, CaII, MgI, TiII, MnII and FeII observed at z = 1.1801 are very close to that observed along the line of sight towards 23 Ori in our Galaxy. The shape of the QSO continuum and the relative depletion of Fe, Ti, Mn and Ca are consistent with the presence of dust at z = 1 (AV = 0.5 mag). Altogether it is found that the HI column density at z = 1 is of the order of 1 to 5 10**21 cm-2, the corresponding metallicity is in the range 1--0.3 Zsol. The objects associated with these two systems could both contribute to the lens together with another possible strong system at z = 1.1727 and the strong Lyman-alpha system at z = 2.974. The probable damped Ly-alpha system at z = 2.974 has 19.8 < log N(HI) < 20.3. The transverse dimension of the absorber is larger than 200 pc. Abundances relative to solar are -2.31, -2.26, -2.10, -2.35 and -2.37 for, respectively, Fe, Al, Si, C and O (for log N(HI) = 20.3). (Abridged)