irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

mailMS.cpp
Go to the documentation of this file.
1 
6 
8 //#include "reGlobalsExtern.hpp"
9 //#include "reFuncDefs.hpp"
11 
12 #include "irods_log.hpp"
13 #include "irods_re_structs.hpp"
14 
15 #include <unistd.h>
16 #include <sys/types.h>
17 #include <pwd.h>
18 
19 
53 int msiSendMail( msParam_t* xtoAddr, msParam_t* xsubjectLine, msParam_t* xbody, ruleExecInfo_t* ) {
54 
55  const char * toAddr = ( char * ) xtoAddr->inOutStruct;
56  const char * subjectLine = xsubjectLine->inOutStruct ? ( char * ) xsubjectLine->inOutStruct : "";
57  const char * body = xbody->inOutStruct ? ( char * ) xbody->inOutStruct : "";
58 
59  if ( int status = checkStringForEmailAddress( toAddr ) ) {
60  rodsLog( LOG_NOTICE, "checkStringForEmailAddress failed for [%s]", toAddr );
61  return status;
62  }
63  if ( int status = checkStringForSystem( subjectLine ) ) {
64  rodsLog( LOG_NOTICE, "checkStringForSystem failed for [%s]", subjectLine );
65  return status;
66  }
67 
68  char fName[] = "/tmp/irods_mailFileXXXXXXXXXX";
69  int fd = mkstemp( fName );
70  if (fd < 0) {
71  rodsLog(LOG_ERROR, "msiSendMail: mkstemp() failed [%s] %d - %d", fName, fd, errno);
72  return FILE_OPEN_ERR;
73  }
74 
75  FILE* file = fdopen(fd, "w");
76  if ( file == NULL ) {
77  rodsLog( LOG_ERROR, "failed to create file [%s] errno %d", fName, errno );
78  return FILE_CREATE_ERROR;
79  }
80 #ifdef solaris_platform
81  if ( strlen( subjectLine ) > 0 ) {
82  fprintf( file, "Subject:%s\n\n", subjectLine );
83  }
84 #endif
85  const char * t1 = body;
86  while ( const char * t2 = strstr( t1, "\\n" ) ) {
87  fwrite( t1, sizeof( *t1 ), t2 - t1, file );
88  fprintf( file, "\n" );
89  t1 = t2 + 2;
90  }
91  fprintf( file, "%s\n", t1 );
92  fclose( file );
93  char * mailStr = ( char* )malloc( strlen( toAddr ) + strlen( subjectLine ) + 100 );
94  if ( mailStr == NULL ) {
95  return SYS_MALLOC_ERR;
96  }
97 
98 #ifdef solaris_platform
99  sprintf( mailStr, "cat %s| mail '%s'", fName, toAddr );
100 #else /* tested for linux - not sure how other platforms operate for subject */
101  if ( strlen( subjectLine ) > 0 ) {
102  sprintf( mailStr, "cat %s| mail -s '%s' '%s'", fName, subjectLine, toAddr );
103  }
104  else {
105  sprintf( mailStr, "cat %s| mail '%s'", fName, toAddr );
106  }
107 #endif
108  int ret = 0;
109  ret = system( mailStr );
110  if ( ret ) {
111  irods::log( ERROR( ret, "mailStr command returned non-zero status" ) );
112  }
113  sprintf( mailStr, "rm %s", fName );
114  ret = system( mailStr );
115  if ( ret ) {
116  irods::log( ERROR( ret, "mailStr command returned non-zero status" ) );
117  }
118  free( mailStr );
119  return 0;
120 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
SYS_MALLOC_ERR
@ SYS_MALLOC_ERR
Definition: rodsErrorTable.h:84
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
checkStringForEmailAddress
int checkStringForEmailAddress(const char *inString)
Definition: stringOpr.cpp:313
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
MsParam
Definition: msParam.h:76
irods::log
void log(const error &)
Definition: irods_log.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
msiSendMail
int msiSendMail(msParam_t *xtoAddr, msParam_t *xsubjectLine, msParam_t *xbody, ruleExecInfo_t *)
Definition: mailMS.cpp:53
update_schema_ids_for_cmake.file
file
Definition: update_schema_ids_for_cmake.py:21
RuleExecInfo
Definition: irods_re_structs.hpp:18
irods_re_structs.hpp
icatHighLevelRoutines.hpp
FILE_OPEN_ERR
@ FILE_OPEN_ERR
Definition: rodsErrorTable.h:494
checkStringForSystem
int checkStringForSystem(const char *inString)
Definition: stringOpr.cpp:296
MsParam::inOutStruct
void * inOutStruct
Definition: msParam.h:80
irods_log.hpp
FILE_CREATE_ERROR
@ FILE_CREATE_ERROR
Definition: rodsErrorTable.h:672