summaryrefslogtreecommitdiffstats
path: root/mailnews/import/src/nsImportMimeEncode.h
blob: 1447d11c4ce9ce00f94232934cdc6a2720157e27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsImportMimeEncode_h__
#define nsImportMimeEncode_h__

#include "mozilla/Attributes.h"
#include "nsImportScanFile.h"
#include "ImportOutFile.h"
#include "nsImportEncodeScan.h"
#include "nsStringGlue.h"
#include "nsIImportMimeEncode.h"


// Content-Type: image/gif; name="blah.xyz"
// Content-Transfer-Encoding: base64
// Content-Disposition: attachment; filename="blah.xyz"

class nsImportMimeEncode : public nsImportEncodeScan {
public:
	nsImportMimeEncode();
	~nsImportMimeEncode();
	
	void	EncodeFile(nsIFile *pInFile, ImportOutFile *pOut, const char *pFileName, const char *pMimeType);

	bool	DoWork(bool *pDone);
	
	long	NumBytesProcessed(void) { long val = m_bytesProcessed; m_bytesProcessed = 0; return val;}

protected:
	void	CleanUp(void);
	bool	SetUpEncode(void);
	bool	WriteFileName(nsCString& fName, bool wasTrans, const char *pTag);
	bool	TranslateFileName(nsCString& inFile, nsCString& outFile);


	virtual bool	ScanBuffer(bool *pDone) override;


protected:
	nsCString             m_fileName;
	nsCOMPtr <nsIFile>    m_pMimeFile;
	ImportOutFile *		m_pOut;
	nsCString			m_mimeType;

	int				m_state;
	long			m_bytesProcessed;
	uint8_t *		m_pInputBuf;
	bool			m_appleSingle;
	
	// Actual encoding variables
	int			m_lineLen;
};


class nsIImportMimeEncodeImpl : public nsIImportMimeEncode {
public:
	NS_DECL_ISUPPORTS

	NS_DECL_NSIIMPORTMIMEENCODE

	nsIImportMimeEncodeImpl();

private:
	virtual ~nsIImportMimeEncodeImpl();
	ImportOutFile *			m_pOut;
	nsImportMimeEncode *	m_pEncode;
};


#endif /* nsImportMimeEncode_h__ */