1
kikov
Automatic Email Interface for NEWS Insertion
  • 2003/10/20 13:53

  • kikov

  • Just popping in

  • Posts: 13

  • Since: 2003/10/2


I am interesting in developing an email interface to insert data into Xoops. (NEWS).
I want to know if it's done so I don't duplicate code.
If it's, I want to know where can I find information about it.

I am talking about an interface to do something like this:

------ Header of the email ------
to: xoops_engine@site.org
from: user@mysite.org
----- Content of the email -----
passwd: xxxxxxxx
type: NEWS
action: add
section: general
title: A NEWS posted by email
content: Hi!, This is my NEWS!
----------------------------------

And when the message is received in the site.org, it is automatically proccessed and a new NEWS is set into the page.

Thx for paying attention
BR.

2
ackbarr
Re: Automatic Email Interface for NEWS Insertion

such an interface is highly dependant on the mailserver software being used on your server and usually could not be managed within the XOOPS application. Most mailservers allow you to forward a message sent to one mbox to another, some allow you to use this forwarding feature to pipe an incoming mail message to an application for processing. I remember a helpdesk application that utilized this feature called Cerberus Helpdesk. I'd look at how they accomplished it for ideas.

3
mike--h
Re: Automatic Email Interface for NEWS Insertion
  • 2003/10/20 14:19

  • mike--h

  • Just popping in

  • Posts: 29

  • Since: 2003/6/22


didnt postnuke used to have a module that did this, postbag or something
also fud forum and mailgust scripts think has this features,
not sure method of how they achieved this

4
kikov
Re: Automatic Email Interface for NEWS Insertion
  • 2003/10/20 14:57

  • kikov

  • Just popping in

  • Posts: 13

  • Since: 2003/10/2


Well...

My first idea is making a PHP script to call the Submit code from the shell...
Quote:

include '/www/docs/os4os.org/mainfile.php';
include_once '/www/docs/os4os.org/modules/news/class/class.newsstory.php';

$module_handler =& xoops_gethandler('module');
$xoopsModule =& $module_handler->getByDirname('news');
$nohtml_db = 1;
echo "XoopsUser:".$xoopsUser."\n";
echo "xoopsModule:".$xoopsModule."\n";
var_dump($xoopsModule);
if ( $xoopsUser ) {
$uid = $xoopsUser->getVar('1');
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
$nohtml_db = empty($nohtml) ? 0 : 1;
}
} else {
echo "xoopsModuleConfig:".$xoopsModuleConfig['anonpost'];
if ( $xoopsModuleConfig['anonpost'] == 1 ) {
$uid = 0;
} else {
redirect_header("index.php",3,_NOPERM);
exit();
}
}
echo "Antes de NEWSSTORY";
$story = new NewsStory();
$story->setTitle("Probando");
$story->setHometext("Mensaje");
$story->setUid(1);
$story->setTopicId(1);
$story->setHostname(xoops_getenv('REMOTE_ADDR'));
$story->setNohtml($nohtml_db);
$nosmiley = isset($nosmiley) ? intval($nosmiley) : 0;
$notifypub = isset($notifypub) ? intval($notifypub) : 0;
$story->setNosmiley($nosmiley);
$story->setNotifyPub($notifypub);
$story->setType('user');
if ( $xoopsModuleConfig['autoapprove'] == 1 ) {
$approve = 1;
$story->setApproved($approve);
$story->setPublished(time());
$story->setExpired(0);
$story->setTopicalign('R');
}
$result = $story->store();

Now, I'm trying to modify this code to be executable from command line... I have to put some vars before including mainfile such as an unreal URL. xoopsModuleConfig doesn't work at the moment.

I have to improve the users managemente :)... just parametrizing it... but at the moment I only want to test if I am able to post a NEWS from shell... The rest is easy...

A filter in the mbox of the xoops@localhost.org user, that parse a text ( simple commands and so ) and then, call the php with their parameters: FROM_USER, NEWS, TOPIC, and so...

BR.


5
kikov
Re: Automatic Email Interface for NEWS Insertion
  • 2003/10/22 11:13

  • kikov

  • Just popping in

  • Posts: 13

  • Since: 2003/10/2


I finally got this...
The filter to parse a email, and the post_news.php command-line script to put something into the DB.

If somebody wanna the code I have it here...

BR

6
Chado
Re: Automatic Email Interface for NEWS Insertion
  • 2003/10/22 15:42

  • Chado

  • Not too shy to talk

  • Posts: 113

  • Since: 2003/6/6 7


Great! Yes, please share with us your code and what we need to do to set it up. Thanks so much!!
Chad

7
kikov
Re: Automatic Email Interface for NEWS Insertion
  • 2003/11/3 0:52

  • kikov

  • Just popping in

  • Posts: 13

  • Since: 2003/10/2


It's a lot dirty!!!

But, it's only an idea...
--------------
just put this in the /etc/aliases file:
Quote:

xoops: "|/bin/parser"


parser.c file
-------------
Quote:

#include <stdio.h>

int main(void)
{
char mycad[1024];
char total[10000];
char *pos;
char XoopUser[1024], XoopPasswd[1024], XoopTitle[1024], XoopMessage[10000], XoopTopic[1024];
printf("Received parameters:\n");
while ( !feof(stdin) )
{
fscanf(stdin,"%[^\n]", mycad );
fgetc(stdin);
if ( strstr ( mycad, "XoopUser:" ) )
{
strcpy (XoopUser, strstr ( mycad, ":" ) + 1);
printf("->XoopUser:%s\n",XoopUser);
}
if ( strstr ( mycad, "XoopPasswd:" ) )
{
strcpy (XoopPasswd, strstr ( mycad, ":" ) + 1);
printf("->XoopPasswd:%s\n",XoopPasswd);
}
if ( strstr ( mycad, "XoopTitle:" ) )
{
strcpy (XoopTitle, strstr ( mycad, ":" ) + 1);
printf("->XoopTitle:%s\n",XoopTitle);
}
if ( strstr ( mycad, "XoopMessage:" ))
{
strcpy (XoopMessage, strstr ( mycad, ":" )+1);
printf("->XoopMessage:%s\n",XoopMessage);
}
if ( strstr ( mycad, "XoopTopic:" ) )
{
strcpy (XoopTopic, strstr ( mycad, ":" ) +1);
printf("->XoopTopic:%s\n",XoopTopic);
}
mycad[0]=0;
}
sprintf( total, "/usr/bin/php4 /usr/share/xoops/post_xoops %s %s %s %s %s", XoopUser, XoopPasswd, XoopTitle,
XoopMessage, XoopTopic, NULL );
printf("Executing %s\n", total);
system ( total );
return 0;
}

-----
Just compile it with gcc parser.c -o parser
Copy it to /bin ( or if your prefer /usr/local/bin and remember to change the path in the aliases file )

and at last... the post_xoops.php file ( it's dirty, dirty dirty... if some hacker from XOOPS could clean it... please!! ). Copy it to /usr/share/xoops/post_xoops
---------------
Quote:

<?php
$myargsKikoV=$GLOBALS['argv'];
$HTTP_SERVER_VARS['REQUEST_METHOD'] ='POST';
$HTTP_SERVER_VARS['HTTP_REFERER'] = 'http://your.url.org/modules/news/submit.php';
$nohtml = 1;
include '/path/to/xoops/mainfile.php';
include_once '/path/to/xoops/modules/news/class/class.newsstory.php';

$module_handler =& xoops_gethandler('module');
$xoopsModule =& $module_handler->getByDirname('news');
$nohtml_db = 1;
$xoopsModuleConfig =& $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid'));
echo "\n";
if (count ($myargsKikoV ) < 5)
{
echo "Usage: php4 ".$myargsKikoV[0]." UserName Password Title Message [Topic]\n";
exit(0);
}
$param_username=$myargsKikoV[1];
$param_password=$myargsKikoV[2];
$param_title=$myargsKikoV[3];
$param_message=$myargsKikoV[4];

if ( count($myargsKikoV) >= 6 )
{
$param_topic=$myargsKikoV[5];
$sql = 'SELECT topic_id FROM '. $xoopsDB->prefix("topics")." WHERE topic_title='".$param_topic."'";
$result = $xoopsDB->query('SELECT topic_id FROM '. $xoopsDB->prefix("topics")." WHERE topic_title='".$param_topic."'");
$topic = array();
$myts =& MyTextSanitizer::getInstance();
while ($myrow = $xoopsDB->fetchArray($result)) {
$topic_id= $myrow['topic_id'];
}
}
$member_handler =& xoops_gethandler('member');
$myts =& MyTextsanitizer::getInstance();
$user =& $member_handler->loginUser(addslashes($myts->stripSlashesGPC($param_username)), addslashes($myts->stripSlashesGPC($param_password)));
if ( ! $user )
{
echo "Login problem\n";
exit(1);
}
$luid=$user->getVar('uid');
$xoopsUser =& $member_handler->getUser($luid);
if ( $xoopsUser ) {
$uid = $xoopsUser->getVar('uid');
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
$nohtml_db = empty($nohtml) ? 0 : 1;
}
} else {
echo "xoopsModuleConfig:".$xoopsModuleConfig['anonpost'];
if ( $xoopsModuleConfig['anonpost'] == 1 ) {
$uid = 0;
} else {
redirect_header("index.php",3,_NOPERM);
exit();
}
}
$story = new NewsStory();
$story->setTitle($param_title);
$story->setHometext($param_message);
$story->setUid($uid['value']);
$story->setTopicId($topic_id);
$story->setHostname(xoops_getenv('REMOTE_ADDR'));
$story->setNohtml($nohtml_db);
$nosmiley = isset($nosmiley) ? intval($nosmiley) : 0;
$notifypub = isset($notifypub) ? intval($notifypub) : 0;
$story->setNosmiley($nosmiley);
$story->setNotifyPub($notifypub);
$story->setType('user');
if ( $xoopsModuleConfig['autoapprove'] == 1 ) {
$approve = 1;
$story->setApproved($approve);
$story->setPublished(time());
$story->setExpired(0);
$story->setTopicalign('R');
}
$result = $story->store();

?>


How it works?

It's quite simple...
When you send a message to xoops@your.host.org, it's passed through a filter ( parser.c ) that parse the email seeking the values.

For example:
Quote:

XoopUser:myuser
XoopPasswd:mypasswd
XoopTitle:This.is.my.news.sent.by.email
XoopMessage:Hi!This.is.my.first.NEWS.sent.by.email.
XoopTopic:Xoops



Then, the values are passed as argument to the php file, that call the functions of XOOPS to add a NEWS.

The stream is:
Email (Evolution,KMail,Outlook) -> MailServer -> Parser -> PostXoops -> Xoops

Yes, I know I have to fix the spaces thing... And let the XoopMessage be more than a line. But this is only a first version to know that it's possible... ( I made everything in just two hours.. )

Comments are welcome!

Thx and greeting

8
Wingz
Re: Automatic Email Interface for NEWS Insertion
  • 2003/11/3 1:46

  • Wingz

  • Just popping in

  • Posts: 71

  • Since: 2002/8/23


I am contantly amazed at tbe talent in the XOOPS community - well done guys!

9
intel352
Re: Automatic Email Interface for NEWS Insertion
  • 2003/12/1 10:12

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


just an fyi, there is a nice Helpdesk app that i've suggested should be ported to xoops, in this thread HERE

that helpdesk app can easily parse emails to add to the queue (or to an already existing ticket), can separate the headers for trash or to show separately, and will even accept attached files

it uses a perl script for users that want a cgi/perl method, but it can also connect to a pop3 server of your choice to get the email, instead


might want to check it out, if it was ported by the Core team, this would benefit the News module, and perhaps even Downloads/Links, etc etc

10
lykoszine
Re: Automatic Email Interface for NEWS Insertion
  • 2003/12/1 10:18

  • lykoszine

  • Module Developer

  • Posts: 244

  • Since: 2002/1/2 2


Someone in the core team is working on an email module that would work from a single catch all pop3 address.

This would be very relevant to that module, I shall pass it along.

Login

Who's Online

228 user(s) are online (147 user(s) are browsing Support Forums)


Members: 0


Guests: 228


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits