Skip to content

Commit 1e14bb0

Browse files
committed
initial commit
0 parents  commit 1e14bb0

File tree

8 files changed

+503
-0
lines changed

8 files changed

+503
-0
lines changed

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (C) <2013> <0xAX>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# POP3
2+
3+
Pop3 - is erlang library which provides work with pop3 protocol.
4+
5+
## Features
6+
7+
* USER/PASS - authorization
8+
* STAT command
9+
* LIST with args command
10+
* Delete message
11+
* RSET
12+
* NOOP
13+
* Retrive message with headers
14+
* quit :)
15+
16+
## Using
17+
18+
First of of all you need to got source code of `pop3` from github. Then go to the root dir of `pop3` build it:
19+
20+
```erlang
21+
./rebar compile
22+
```
23+
24+
Now you can use it:
25+
26+
```erlang
27+
% start pop3 application
28+
application:start(pop3).
29+
% Some auth data
30+
Data = {"[email protected]", "password", "pop.mail.com", 110},
31+
% Get stat
32+
{ok, MessageCount, Size} = pop3:get_stat(Data),
33+
% Data with message id
34+
Data = {"[email protected]", "password", "pop.mail.com", 110, 5},
35+
% Delete message
36+
ok = pop3:delete(Data2),
37+
% RSET it
38+
pop3:rset(Data),
39+
% end of session
40+
pop3:quit(Data).
41+
```
42+
43+
## Contribute
44+
45+
* Fork `pop3` repo
46+
* Make changes
47+
* Pull request
48+
* Thank you.
49+
50+
## TODO
51+
52+
* Add ssl support
53+
* Add APOP
54+
* ADD TOP
55+
56+
## AUTHORS
57+
58+
[@0xAX](https://twitter.com/anotherworldofw)
59+
60+
## Support
61+
62+
<a href='http://www.pledgie.com/campaigns/19013'><img alt='Click here to lend your support to: pop3 erlang library and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/19013.png?skin_name=chrome' border='0' /></a>

rebar

116 KB
Binary file not shown.

src/pop3.app.src

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{application, pop3,
2+
[
3+
{description, "Lightweight pop3 library for erlang application."},
4+
{vsn, "0.1"},
5+
{registered, []},
6+
{applications, [
7+
kernel,
8+
stdlib,
9+
ssl
10+
]},
11+
{mod, { pop3_app, []}},
12+
{env, []}
13+
]}.

src/pop3.erl

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
-module (pop3).
2+
3+
-export([start/0]).
4+
5+
% pop3 api
6+
-export([get_stat/1,quit/1, get_list/1, delete/1, get_message/1]).
7+
-export([noop/1, rset/1]).
8+
9+
-spec start() -> ok.
10+
start() ->
11+
application:start(pop3).
12+
13+
%% @doc Send `STAT` command to pop3 server
14+
%% @end
15+
-spec get_stat({User :: string(), Password :: string(),
16+
Server :: string(), Port :: integer()}) -> error | {ok, MessageCount :: integer(), Size :: integer()}.
17+
get_stat({User, Password, Server, Port}) ->
18+
% start new pop3 client
19+
{ok, Pid} = pop3_sup:start_pop3_client(User, Password, Server, Port),
20+
gen_server:call(Pid, send_stat).
21+
22+
%% @doc Send `quit`
23+
%% @end
24+
-spec quit({User :: string(), Password :: string(),
25+
Server :: string(), Port :: integer()}) -> ok.
26+
quit({User, Password, Server, Port}) ->
27+
% start new pop3 client
28+
{ok, Pid} = pop3_sup:start_pop3_client(User, Password, Server, Port),
29+
gen_server:cast(Pid, quit),
30+
ok.
31+
32+
%% @doc Get message list
33+
%% @end
34+
-spec get_list({User :: string(), Password :: string(),
35+
Server :: string(), Port :: integer()}) -> error | {ok, MessageCount :: integer(), Octets :: integer()}.
36+
get_list({User, Password, Server, Port}) ->
37+
% start new pop3 client
38+
{ok, Pid} = pop3_sup:start_pop3_client(User, Password, Server, Port),
39+
gen_server:call(Pid, get_list);
40+
41+
get_list({User, Password, Server, Port, MessageId}) ->
42+
% start new pop3 client
43+
{ok, Pid} = pop3_sup:start_pop3_client(User, Password, Server, Port),
44+
gen_server:call(Pid, {get_list, MessageId}).
45+
46+
%% @doc Delete message
47+
%% @end
48+
-spec delete({User :: string(), Password :: string(),
49+
Server :: string(), Port :: integer(), MessageId :: integer()}) -> ok.
50+
delete({User, Password, Server, Port, MessageId}) ->
51+
% start new pop3 client
52+
{ok, Pid} = pop3_sup:start_pop3_client(User, Password, Server, Port),
53+
gen_server:cast(Pid, {delete, MessageId}),
54+
ok.
55+
56+
%% @doc Send `RSET`
57+
%% @end
58+
-spec rset({User :: string(), Password :: string(),
59+
Server :: string(), Port :: integer()}) -> ok.
60+
rset({User, Password, Server, Port}) ->
61+
% start new pop3 client
62+
{ok, Pid} = pop3_sup:start_pop3_client(User, Password, Server, Port),
63+
gen_server:cast(Pid, rset),
64+
ok.
65+
66+
%% @doc Send `NOOP`
67+
%% @end
68+
-spec noop({User :: string(), Password :: string(),
69+
Server :: string(), Port :: integer()}) -> ok.
70+
noop({User, Password, Server, Port}) ->
71+
% start new pop3 client
72+
{ok, Pid} = pop3_sup:start_pop3_client(User, Password, Server, Port),
73+
gen_server:cast(Pid, noop),
74+
ok.
75+
76+
%% @doc Get message with headers
77+
%% @end
78+
-spec get_message({User :: string(), Password :: string(),
79+
Server :: string(), Port :: integer(), MessageId :: integer()}) -> error | {ok, MessageWithHeaders :: string()}.
80+
get_message({User, Password, Server, Port, MessageId}) ->
81+
% start new pop3 client
82+
{ok, Pid} = pop3_sup:start_pop3_client(User, Password, Server, Port),
83+
gen_server:call(Pid, {get_message, MessageId}, infinity).

src/pop3_app.erl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-module(pop3_app).
2+
3+
-behaviour(application).
4+
5+
%% Application callbacks
6+
-export([start/2, stop/1]).
7+
8+
%% ===================================================================
9+
%% Application callbacks
10+
%% ===================================================================
11+
12+
start(_StartType, _StartArgs) ->
13+
% start main supervisor
14+
pop3_sup:start_link().
15+
16+
stop(_State) ->
17+
ok.

0 commit comments

Comments
 (0)