-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.h
101 lines (85 loc) · 2.23 KB
/
message.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* File: message.h
* Author: Wouter Van Rossem
*
*/
#ifndef _MESSAGE_H
#define _MESSAGE_H
#include <string>
#include <fstream>
#include <stdio.h>
#include <iostream>
#include <stdexcept>
#include <sstream>
#include <cstddef>
#include <algorithm>
#include <math.h>
/** The Message class represents a message in a maildrop
* Operations on the message file are executed by opening
* a filestream with the _file_path as path
*/
class Message
{
public:
/** Constructor for Message
* @param number The number of this message
* @param filepath String representing the path to the message file
*/
Message (unsigned int number, const std::string& filepath);
/** Destructor for message
* If the message was marked as deleted, it will be deleted now
* @exception std::runtime_error If the message file can't be deleted
*/
virtual ~Message ();
/**
* @return Bool indicating if the message is marked as deleted
*/
bool deleted () const
{
return _deleted;
}
/** Overloaded deleted method
* @param mark Mark or unmark the message as deleted
*/
void deleted (bool mark)
{
_deleted = mark;
}
/**
* @return The number of the message
*/
int number () const
{
return _number;
}
/**
* @return the size of the file in bytes
*/
unsigned long size () const;
/**
* @return A string which contains the text in the message file
* @exception std::runtime_error If the message file can't be opened
*/
std::string message_string () const;
/** Overloaded message_string method
* @param n The top n lines of the message only
* @return A string containing the top n lines of the message file
*/
std::string message_string (int n) const;
/**
* @return A string which is the filename = uidl in this implementation
*/
std::string uidl () const;
/** Overloaded << operator, sends some information of the message
* to the ostream
*/
friend std::ostream& operator<< (std::ostream& os, const Message& msg);
private:
/* The number of the message */
unsigned int _number;
/* A bool indicating if the message is marked a deleted */
bool _deleted;
/* String containing the path to the message file */
std::string _file_path;
};
#endif /* _MESSAGE_H */