code: function buildAttMessageFunction(attachment, attachmentloc) {
          let filename = attachment.params.name;
          let encoding = attachment.encoding;
  
          return function(msg, seqno) {
              let prefix = '(#' + seqno + ') ';
              msg.on('body', function(stream, info) {
                  if (attachmentloc) {
                      filename = attachmentloc + filename;
                  }
                  // Create a write stream so that we can stream the attachment to file;
                  console.log(prefix + 'Streaming this attachment to file', filename, info);
                  let writeStream = fs.createWriteStream(filename);
                  writeStream.on('finish', function() {
                      console.log(prefix + 'Done writing to file %s', filename);
                  });
  
                  // stream.pipe(writeStream); this would write base64 data to the file.
                  // so we decode during streaming using
                  if (toUpper(encoding) === 'BASE64') {
                      // the stream is base64 encoded, so here the stream is decode on the fly and piped to the write stream (file)
                      stream.pipe(base64.decode()).pipe(writeStream);
                  } else {
                      // here we have none or some other decoding streamed directly to the file which renders it useless probably
                      stream.pipe(writeStream);
                  }
              });
              msg.once('end', function() {
                  console.log(prefix + 'Finished attachment %s', filename);
              });
          };
      }
docs: __DOCSPLACEHOLDER__
  
  @param {any} attachment __DOCSPLACEHOLDER__
  @param {any} attachmentloc __DOCSPLACEHOLDER__
  @return {function} attachMessageFunction